开发者

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

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 Pric开发者_运维问答e" appears in the table.

CLICK HERE TO SEE IT IN ACTION ON MY SITE


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.


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).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜