javascript - Obtaining Upper level li text -
javascript - Obtaining Upper level li text -
so have list on page
<li class="head"> <b>introduction</b> <ul> <li class="sub">somethingsomething</li> </ul> </li>
this list beingness used sortable, user can decide on order, , passing info grails controller utilize in application logic. so, trying read in, , place text contained in "head" , "sub" classes in 2 different arrays. however, when utilize jquery selector obtain head elements, , obtain text attribute of element, contains within list well.
$('#divname').find("ul > li.head").each(function() { var current = $(this); console.log(current.text()); });
results in introductionsomethingsomething
is there way obtain 'introduction' text list, , ignore text in nested <ul>
, <li.sub>
? due beingness nested, unable figure out how utilize jquery's :not() selector
you can find b
tag using jquery tagname selector.like this:
var current = $(this).find('b'); console.log(current.text());
working demo
javascript jquery
Comments
Post a Comment