<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 开发者_JAVA百科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!
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');
});
If you have only one span as in your html...
$('a.ui-link').live('click', function(){
var id = $('span', $(this).closest('li')).attr('id');
});
精彩评论