Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get id attribute from another element in same list item with Jquery

Tags:

html

jquery

<li class="ui-li ui-li-static ui-body-c">
    <p class="ui-li-aside ui-li-desc"></p>
    <span id="122"></span>
    <h3 class="ui-li-heading"></h3>
    <p class="ui-li-desc"></p>
    <p class="ui-li-desc"><a class="ui-link">Report</a></p>
</li>

So here is my HTML markup.

Goal: I need JQuery code that will give me the id value of the <span> element (so in this case: 122) within the same <li>, when I click the <a> in that same <li>.

How would I do this?

Thanks!

like image 272
Scott Avatar asked Nov 26 '25 09:11

Scott


1 Answers

Assuming you only have one span tag in your list items, you should be able to get your span's id with this:

$('a.ui-link').click(function(){
   var id = $(this).closest('li').find('span:first').attr('id');
});
like image 53
Phil.Wheeler Avatar answered Nov 28 '25 21:11

Phil.Wheeler