Monday, 15 July 2013

javascript - Get only direct element value with jquery -



javascript - Get only direct element value with jquery -

lets have next menu:

class="snippet-code-js lang-js prettyprint-override">$(document).ready(function() { alert($('ul li').html()); }); class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul class="menu"> <li><i class="font-icon"></i> users <ul> <li>overview</li> </ul> </li> </ul>

as can see homecoming get:

<i class="font-icon"></i> users <ul> <li>overview</li> </ul>

now problem i'm interested in: <i class="font-icon"></i> users. there way homecoming without putting in div or span? tried .text() gave me actual text users (obviously).

thanks in advance

i think solution: demo

$(document).ready(function() { var i=$('ul li').html(); var ul=$('ul li').find('ul')[0].outerhtml; i=i.replace(ul,''); alert(i); });

javascript jquery html

No comments:

Post a Comment