$("ul li:first-child") Selects the first <li> element of every <ul> - Javascript jQuery

Javascript examples for jQuery:Selector

Description

$("ul li:first-child") Selects the first <li> element of every <ul>

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("ul li:first-child").hide();
    });/*  w ww .  j  a  v a  2s.co m*/
});
</script>
</head>
<body>

<p>List 1:</p>
<ul>
  <li>A</li>
  <li>B</li>
  <li>Tea</li>
</ul>

<p>List 2:</p>
<ul>
  <li>A</li>
  <li>B</li>
  <li>Tea</li>
</ul>

<button>Click me</button>

</body>
</html>

Related Tutorials