Avaz
Avaz

Reputation: 29

Hide all li tags with jquery

Please help me to complete my code. I want to hide all <li> tags on body onload.

$(document).ready(function () {
$('li > ul').hide();    
});

Please give me the right variant for the code!

Upvotes: 1

Views: 5917

Answers (2)

moe
moe

Reputation: 29704

It's ul > li, not li > ul

$(document).ready(function () { $('ul > li').hide(); });

Upvotes: 5

Hussein
Hussein

Reputation: 42808

$(function(){
  $('li').hide()
})

This will search and hide every <li> tag on the page. It is better to narrow down the search to improve performance Ex: $('#mydiv li') where mydiv is the id of the ul tag <ul id="mydiv">.

Upvotes: 3

Related Questions