BumbleBee
BumbleBee

Reputation: 10789

Get the Id/name of an element from dynamically generated HTML JQuery

How can I get the id or name of input element of type="text" from dynamically generated HTML.

I need to get the Id of <input name="ctl00$DefaultContent$ctl2" type="text">

 <tr>
    <td class="TextBold" >1.</td>
    <td class="TextBold" >Content for Question 1:</td>
    <td class="TextBold" >
      <input name="ctl00$DefaultContent$ctl2" type="text" class="TextNormal" />
    </td>
  </tr>

Thank in advance

BB

Upvotes: 2

Views: 3317

Answers (1)

dknaack
dknaack

Reputation: 60486

Descriptiom

Your <input name="ctl00$DefaultContent$ctl2" type="text" class="TextNormal" /> has no id attribute. But you can get a collection of every input type text using this selector $("input[type='text']). I think you want to get the name attribute.

Check out the sample and this jsFiddle Demonstration.

Sample

$(function() {
    $("input[type='text']").each(function() {
       alert("id = " + $(this).attr("id")); 
       alert("name = " + $(this).attr("name")); 
    });
});

More Information

Update

Your input element has a class attribute. You can get all elements that has this class using

$(".TextNormal").each(function() {
    alert("id = " + $(this).attr("id")); 
    alert("name = " + $(this).attr("name")); 
});

Upvotes: 2

Related Questions