I need to detect a specific class from a color picker and then change the class of a header tag.
// To locate the specific header id with the 'bgt' CSS class. Detecting the id from a div that contains the '.ss' CSS class.
$(document.body).on('click', '.bgt', function(e) {
e.preventDefault();
id = $(this).closest('div').find('.ss').attr('id');
var $this = $('#h'+id);
var $dv = $this.closest('div');
var nstr= $dv.attr('class');
var newstrt = nstr;
// Header tag where I am adding the class
$("#h"+id).addClass(newstrt);
This code sometimes works, but other times it does not work. Any assistance would be greatly appreciated.