Posted in jquery
4:25 am, June 21, 2021

check if a ul contains a ul li

i could not find a way to do this with just raw css so i had to use jquery /sad

HTML

<ul id='targetul'>
<li>item 1</li>
<li>item 2
<ul>
<li>nested ul item 3</li>
</ul>
</li>
<li>item 4</li>
</ul>

Javascript

$(document).ready(function(){
  // this one sets the whole list to red as that is the target
	//$("#targetul").has("ul li").css("background", "#F00");
  
  // this one checks if the target ul has a ul li and then sets that ul li to red background
  if($("#targetul").has("ul li")) { 
    $("#targetul ul li").css("background", "#F00");
  }
});
  • item 1
  • item 2
    • nested ul item 3
  • item 4

No Items Found.

Add Comment
Type in a Nick Name here
 
Page Views

This page has been viewed 249 times.

Search Code
Search Code by entering your search text above.
Welcome

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
Most people can do absolutely awe-inspiring things,” he said. “Sometimes they just need a little nudge.
Unknown