+ 2
add class to $(el).contents()
hello, I've this: var headers = $('h1, h2, h3').contents(); for(var i=0; i < Object.keys(headers).length-2; i++) { if(headers[i].data) { // security var d = headers[i].data; var headerClass = d.replace(' ','-').toLowerCase()+'-'+i; // here is my question : how to set the class headerClass to my headers[i] ? } }
3 ответов
+ 5
header[i].addClass(headerClass);
+ 2
Toni Isotalo `headers[i].addClass is not a function`
I already tried ^^
And for
headers[i].parentElement.classList.add = headerClass;
I dont have error but any header have class
If I remove the .parentElement I've same error as above
+ 1
then it is
$(headers[i]).addClass(headerClass);