jQuery--(3)選擇器

jQuery選擇器包括
#1.元素選擇器
$("p"):表示選取全部的<p>元素
$("p.info"):表示選擇全部class="info"的<p>元素
$("p#demo"):表示選取全部id="info"的<p>元素
#2.屬性選擇器
$("[href]"):選擇全部帶有href屬性的元素
$("[href='#']"):選擇全部帶有href屬性 值等於"#"的元素 #3.css選擇器
該選擇器能夠改變html元素的css屬性
以下是改變p元素的顏色爲紅色
$("p").css("background-color","red")
經常使用選擇器實例
$(this):選取的當前html元素
$("#test1"):表示選取id="test1"的元素javascript

實例css

<html>
<head>
<meta content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery-3.1.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#test1").click(function(){
  $(this).hide();
  });
});
</script>
</head>
<body>
<p id="test1">If you click on me, I will disappear.</p>
</body>
</html>
相關文章
相關標籤/搜索