2
I have the following list:
<ul id = "qualquer">
<li id = "listitem1" class = "middle_item">
</li>
<li id = "listitem2">
</li>
<li id = "listitem3">
</li>
</ul>
In my problem, the class = "middle_item" may be in any li, but at this moment, by chance, it lies in the first li.
I created the following javascript, to try to catch the id of li that has the class = "middle_item"
var i = $("#qualquer .middle_item").attr('id').text();
alert(i);
but the following error is appearing to me:
Uncaught Typeerror: $(...). attr(...). text is not a Function
Any suggestions?
If
middle_itemhas only one element, just do$($('.middle_item')[0]).attr('id');, nay?– Felipe Avelar
Do you want to do what? Show the content of li?
– Jefferson Alison
My fault, I created this example to simplify the original problem. The
middle_itemhas more than one element– msm.oliveira
But you want to catch the
idof all themiddle_items?– Felipe Avelar
@Jeffersonalison I intend to show the id of li
– msm.oliveira
@Felipeavelar No. I just want to get the id of the li that has the class
middle_item– msm.oliveira
But if several
lis may havemiddle_item, then you will have several ids...– Felipe Avelar