0

I have a table with 5 rows and four td's that am building dynamically. On one of the tds' have an input tag inside it, how can i find it using Jquery?

My code:

<table id="mytable">
  <tr>
    <td>number</td>
    <td>date</td>
    <td><input type="text" id="row1" value="" /></td>
    <td>amount</td>
  </tr>
</table>

I have tried this but nothing;

$("#mytable #row1")

Gath

5 Answers 5

2

You should be able to get to the input by simply using $('#row1')

3
  • I thought so, but something is not right! even with that it does not work! but if i create the input tag normally and give an id then use the $("#idname") idom, it works! but for the dynamically created inputs...nothing!
    – gath
    May 26, 2011 at 14:58
  • @gath how are you creating it dynamically?
    – Matt
    May 26, 2011 at 15:01
  • Sorry guys, i saw were i was goofing! when building the input tag id dynamically i was not doing it right. Thanks it works fine.
    – gath
    May 26, 2011 at 15:03
1

the following should work just fine:

$('#row1')

an Id is always unique (or supposed to be) so you can target it directly

1

if your using IDs as selectors then by definition they are unique so just use

$("#row1")
0

As others have mentioned, your ids should be unique. However, I would like to point out that $('#id1 #id2') also works fine. Here is an example: http://jsfiddle.net/DUqwd/

0

I have tested and $("#mytable #row1") worked fine. You can use $("#mytable td input") as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.