Posted in jquery
4:22 am, June 15, 2021

jquery check if a sub element exists

this can be done with .length


<div class="menu">
<li><a href="#!">menu</a>
<li><a href="#!">sub1</a>
<li><a href="#!">sub2</a></li>


	$('.menu > ul > li > a').click(function(e) {
		if($(this).closest('li').find('ul').length) {
    	  var message = "the 1st ul li a also contains a ul";	

No Items Found.

Add Comment
Type in a Nick Name here
Page Views

This page has been viewed 235 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.


Random Quote
I believe that success can be measured in the number of uncomfortable conversations you're willing to have.