开发者

jQuery.find() IE7 bug?

I have a few lines of code where I use this function, but it seems to only find the 1st element in IE7. Works in IE8/FF/Chrome.

$(document).find("#JobID").attr('checked',开发者_Python百科 $('#CheckAll').is(':checked'));

I also have a similar line which only finds the first element.

$(document).find("#JobID").each(function() { ... }

Does anyone know if this is a known bug or a workaround? Maybe I'm not using the proper method?


$(document).find("#JobID") gets the element with id JobID within the document. IDs are unique within a document (see [1]), so there should be at most one element that matches. Use a class (e.g. $('.JobId')) instead.

1: http://www.w3.org/TR/html401/struct/global.html#h-7.5.2


You should be using the code below:

$("#JobID").each(function () { ... });

There isn't any reason to be using $(document).


Your problem is unique IDs, no two elements should share an ID (this isn't valid HTML), it seems you hav a bunch of id="JobID" in there. This should instead be class="JobID" and the selector is then:

$(".JobID").attr('checked', $('#CheckAll').is(':checked'));


'#' is a document id selector (the id="" on an element). Every dom id must be unique, so chances are you have the same dom id more than once and IE7 is doing something weird. However since it is not allowed anyway, its not surprising that something weird is happening.

Change your selector to be something other than dom id and it should work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜