0

I create a variable from a html object

var li = $(this).closest('li');

How do I now select inner html objects from this variable eg span. I have tried

li.span

but no luck.

4

2 回答 2

2

You can use context to pass the variable with selector. You can learn more about selector and context here

var li = $(this).closest('li');
$('span', li)
htmlOfFirstSpan = $('span', li).html();

This will give you span elements within li

于 2012-12-14T11:31:32.157 回答
1

This should work:

var li = $(this).closest('li');
$(li).innerHtml();

You could also do:

$(li).('span').html();
$(li).('.someClass').html();
于 2012-12-14T11:34:28.873 回答