Answer the question
In order to leave comments, you need to log in
How to add a class if the tag has a specific style?
If the h1 tag has styles "text-align:center" then add a class to this tag. Here is an example of code that I am trying to write myself, but it adds a class to all h1 tags on the page
$('h1').each(function (){
if($('h1').css('text-align') == 'center') {
$(this).addClass('centered');
} else {
$(this).removeClass('centered');
}
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question