views:

81

answers:

4

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', $('#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?

+1  A: 

You should be using the code below:

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

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

Garrett
thanks for the tip!
rushonerok
+1 important tip. still $('#anything').each() doesn't make much sense :)
naugtur
I wasn't worried about fixing he actual code, just rather his selector.
Garrett
+4  A: 

$(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

kevingessner
+1 lol this is exactly what I wrote in the comments, but you beat me to it
jmein
this worked. thank you!
rushonerok
+1  A: 

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'));
Nick Craver
thanks this worked!
rushonerok
+1  A: 

'#' 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.

Richard