开发者

jQuery .each is giving different results on different browsers but no errors. It counts the elements wrong, but why?

I need to add the one attribute of all of a certain element to an array:

Here is the html:

<a class="umb" name="/wordpress/images/custom-slideshow/image1.jpg">  
<a class="umb" name="/wordpress/images/custom-slideshow/image2.jpg">  
<a class="umb" name="/wordpress/images/custom-slideshow/image3.jpg">

Here is the jQuery

var theImages = new Array();

$('.umb').each(function(){

    theImages.push($(this).attr('name'));

});

alert(theImages.length);

t开发者_StackOverflow中文版his alerts different numbers in different browsers

in Firefox "15"

in IE8 "3"

in Chrome "6"

in Opera "3" in Safari "12"

The right answer is of course "3". Can't figure out why this is happening.


Well on a quick test of this I get 3 in Safari 5, but it could be because different browsers will attempt to correct the unclosed anchor tags in different ways (assuming that wasn't a paste error). Each anchor should should have a </a> at the end.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜