PDA

View Full Version : correct selector?



ashulm2
Jan 8th, 2010, 05:50 AM
Can anyone tell me what I have done wrong here? I have the following html code



<div id='group1'>
<tr class='time'>
<td colspan='3' name='1262815200'></td>
</tr>

<tr>
<td class='timeleft group1' name='1262815200' colspan='3'></td>
</tr>

<tr class='game'>
<td><input type='radio' name='G1' value='NYJ'>NYJ</td>
<td><input type='radio' name='G1' value='BUF'>BUF</td>
<td><select name='G1P' class='points' tabindex = '1'></select></td>
</tr>

</div>



and when I use the selector $('#group1 input) it does not select anything (namely the inputs in this code). But when I use the selector $('div input') it will select them (and more on the page which I don't want). Is anyone able to see what I have done wrong? I've tried everything I can think of in terms of testing, and I have narrowed it down to the selector. Thanks.

Old Pedant
Jan 8th, 2010, 08:28 AM
Really should be in the jQuery forum.

But feels like a bug in jQuery to me who doesn't use jQuery.

Clearly you could do it in conventional JS via

var inputs = document.getElementById("group1").getElementsByTagName("input");

Ahhh...something just occurred to me: Do you perhaps accidentally have more than one id="group1" on the page???

TinyScript
Jan 8th, 2010, 08:38 AM
and when I use the selector $('#group1 input) it does not select anything

the input has to be in the td with id group1 since that's what your jquery seems to want to do
<tr>
<td class='timeleft group1' name='1262815200' colspan='3'> <input type='radio' name='G1' value='NYJ'>NYJ</td>
</tr>

Kor
Jan 8th, 2010, 09:55 AM
You have rather an HTML/XHTML coding error.

The problem is that you gave a name attribute to your TD element, which is deprecated in HTML and even illegal in XHTML.

See also:
http://www.w3.org/TR/xhtml1/#C_8

Your identifier should be rather an id, not a name. But the id must be unique on document/session. name is to be safety used only for form's elements (INPUT, SELECT, TEXTAREA, BUTTON, OBJECT).

On the other hand, according to the W3C, name and id tokens can not start with a digit, They must begin with a letter.

Old Pedant
Jan 8th, 2010, 08:41 PM
Interesting. I wonder why jQuery would care about that. I, perhaps foolishly, assumed that under the covers jQuery would convert that selector into the basic JS code I showed. Guess not.

Kor
Jan 8th, 2010, 09:23 PM
Interesting. I wonder why jQuery would care about that.
I don't like libraries like JQuery or whichever too much ( I prefer to write my own codes most of the time), but in this case they have no fault. They supposed that the coders should know HTML and CSS, at least on basics. :)

Old Pedant
Jan 8th, 2010, 09:27 PM
Agree with you on all points. Just curious why the illegal names would affect the particular operation. Ah, well. Not important.