jquery .find or .closest then addclass not working in IE or Chrome

6k Views Asked by At

Works in FireFox. Does not work in IE8 or Chrome:

<script>
$('.PageText_L657n').closest('td').find('.pricecolor').addClass('ice1');
</script>

Should be a line-through "Regular Price:$ XX.XX" if "Click To Get Today's Special Price" appears in the table.

CLICK HERE TO SEE IT IN ACTION ON MY SITE

2

There are 2 best solutions below

1
On BEST ANSWER

Wrap your code in ready handler:

<script>
$(function(){
  $('.PageText_L657n').closest('td').find('.pricecolor').addClass('ice1');
});
</script>

Since you are manipulating the DOM, you need the ready handler which firs as soon as DOM becomes ready.

Also make sure element with class PageText_L657n is there is pointed out by @T.J Crowder.

1
On

There's nothing in the source of that page with the PageText_L657n class. Also, you're executing that code before there's much of anything in the DOM (either put it at the bottom, just before your closing body tag, or use the ready function).