I have a html that contains below content:
<div class="ui-btn-text">
<a id="12323" class="listviewLines ui-link-inherit" href="" /></div>
<div class="ui-btn-text">
<a id="23534" class="listviewLines ui-link-inherit" href="" /></div>
<div class="ui-btn-text">
<a id="12312" class="listviewLines ui-link-inherit" href="" /></div>
I want to extract the id value based on the index of the tag, so I write below function:
function getId(index) {
$('.ui-btn-text > a').each(function(i) {
if (index == i) {
alert($(this).attr("id"));
return ($(this).attr("id"));
}
});
}
and then when I call getId(0), the result is “undefined”. I am new to javascript, could anyone help me?
Also, is there a function in jQuery that could directly return content with a index parameter, without iterate all children?
Try
this is zero based, of course.