Home  >  Q&A  >  body text

jquery hierarchical selector problem I tested and found out why there is no difference between ul>li and ul li?

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>Document</title>

<script type="text/javascript" src="jquery/jquery-3.3.1.min.js"></script>

</head>

<body>

<script>

$(document).ready(function(){

// $('ul>li').css('list-style','none')

$('ul li').css('list-style','none')

// $('label input').css('height','100px')

// $('input button').css('height','100px')

$('label~input').css('background','pink')

})

</script>

<ul>

<li>1</li>

<li>1

<li>2</li>

</li>

<li>1

<div>

<li>3

<li>4

<ul>

<li>5</li>

</ul>

</li>

</li>

</div>

</li>

<li>1</li>

<li>1</li>

</ul>

<form action="">

<label for="">姓名</label>

<input type="text"><button>按钮</button><br>

<input type="text"><button>按钮</button><br>

<input type="text"><button>按钮</button><br>

<input type="text"><button>按钮</button><br>

<input type="text"><button>按钮</button><br>

</form>

</body>

</html>


虎哥虎哥2104 days ago1180

reply all(3)I'll reply

  • 粽叶飘香

    粽叶飘香2019-02-13 08:52:19

    ul>li Only search for son elements, except for son elements, other elements are not found.

    ul li Search for all elements

    reply
    0
  • 灭绝师太

    灭绝师太2019-02-11 17:54:18

    ul>li: Find the li that is the direct child element of ul
    ul li: Find all the li below ul


    ##

    reply
    0
  • Cancelreply