开发者

Why is query failing in IE only

My query开发者_Python百科 works great, but then I check it on IE and it is a disaster. I am wondering if it is the parent part of the code. The parents are trying to reach the first <table> containing the info. Is there an easier way to get to the table directly?

 <script>
 if ($('b:contains("Choose a sub category:")').length > 0) {
 var newSubnav = document.createElement( 'ul' );
 $(newSubnav).addClass("sub_categories_holder");
  $('b:contains("Choose a sub category:")').parent().parent().parent().parent().parent().parent().parent().prepend( newSubnav );

 $('a.subcategory_link').appendTo($('ul.sub_categories_holder'));
 $('a.subcategory_link').wrap("<li class='sub_categories'></li>");
 $('li.sub_categories').before("<li class='sub_categories_divider'></li>");
 $("li.sub_categories_divider:eq(0)").remove();

 $("b:contains('Choose a sub category:')").parent().parent().parent().parent().parent().remove();
 $("img[src='/v/vspfiles/templates/GFAR NEW NAV/images/Bullet_SubCategory.gif']").remove();
 $("td.colors_backgroundneutral").css("background-color","transparent");
 $("td.colors_backgroundneutral").children(':first-child').attr("cellpadding","0");
 };

 </script>


Unless you provide your markup(at least a dummy one) it's all guess that you are gonna get.

  1. Instead of .parent().parent().parent().parent().parent().parent().parent().prepend( newSubnav ); check if you can use .parents(). This will return you the parents all the way up to HTML. You can even use selectors as parents(selector) to filter. Read more on the jquery api page.

  2. Since you are using jQuery, you can use $("ul") instead of document.createElement("ul")

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜