jQuery獲取當前元素的下一級子元素程式碼例項

admin發表於2017-03-27

本章節介紹一下如何利用jQuery獲取當前元素的下一級子元素。

程式碼例項:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
#box{
  width:300px;
  height:100px;
  background:#CCC;
}
#box div{
  width:100px;
  height:50px;
  background:red;
  margin:0px auto;
}
</style>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#box").children().css("border","5px solid blue");
})
</script>
</head>
<body>
<div id="box">
  <div>softwhy.com</div>
</div>
</body>
</html>

上面的程式碼實現了我們的要求,具體可以參閱jQuery children()一章節。

相關文章