HTML:
<li class="widgetcontainer widget_text" id="text-3">
<h3 class="widgettitle">Static Ad</h3>
<div class="textwidget"><img alt="" src="static/announcement.png"></div>
</li>
jQuery:
if( $('.widget_text')[0] ) {
$('.widgettitle').each(function() {
if ( $(this).containts('Static Ad') ) {
$(this).parent().addClass('myclass');
}
});
}
… isn’t working. Neither:
if( $('.widget_text')[0] ) {
$('.widget_text').each(function() {
if ( $(this).children('h3:contains:("Static Ad")') ) {
$(this).parent().addClass('static-ad');
}
});
}
How do I fix?
Thanks!
You have a typo:if ( $(this).contains('Static Ad') ) {Try:
or
You have an additional colon
:in your code (remove it) and I think you have to removeparent().Besides that, there is no need to test for
$('.widget_text')[0]. If there is no element with classwidget_text,$('.widget_text').each()won’t do anything anyway 😉