javascript - Get the size of the parent LI inside an UL? -


how can modify below code parent li within first ul , variable sub li of given sub ul?

	$(function () {  		var vulsize = $("ul li").size();  		console.log(vulsize);  	});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>  <ul>  		<li>first</li>  		<li>second  			<ul>  				<li>second sub 1</li>  				<li>second sub 2</li>  			</ul>  		</li>  		<li>third</li>  		<li>third  			<ul>  				<li>third sub 1</li>  				<li>third sub 2</li>  			</ul>  		</li>  	</ul>

fiddle: http://jsfiddle.net/0sp9pohr/

you can ignore li's descendants of li like

$(function() {    var vulsize = $("ul li:not(li li)").size();    snippet.log(vulsize);  });
<!-- provides `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->  <script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <ul>    <li>first</li>    <li>second      <ul>        <li>second sub 1</li>        <li>second sub 2</li>      </ul>    </li>    <li>third</li>    <li>third      <ul>        <li>third sub 1</li>        <li>third sub 2</li>      </ul>    </li>  </ul>


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -