开发者

add class and keep checking rest of document

I am trying to add a class to a bold element only if the bold element does not already have the class specified. Can someone please tell me what I am missing. It stops running after it finds one that fails instead of checking each.

 if ($("font[size='3'] b").hasClass('dont_run')) {}
 else {$("fo开发者_Python百科nt[size='3'] b").addClass('barcode_needed')
 };


$('font[size="3"] b:not(.dont_run)').addClass('barcode_needed');

Using the :not selector will achieve this easily.


Couple things here. Is dont_run a class or a tag? if its a class it should look like this:

$("font[size='3'] b").hasClass('.dont_run')

second, do you plan on doing more in the if else statement? if not then you should use the shorthand version mentioned by Brad Christie

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜