Reputation: 10789
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
Reputation: 60486
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.
$(function() {
$("input[type='text']").each(function() {
alert("id = " + $(this).attr("id"));
alert("name = " + $(this).attr("name"));
});
});
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