首頁  >  文章  >  web前端  >  jquery透過closest選擇器修改上級元素的方法_jquery

jquery透過closest選擇器修改上級元素的方法_jquery

WBOY
WBOY原創
2016-05-16 16:09:101309瀏覽

本文實例講述了jquery透過closest選擇器修改上級元素的方法。分享給大家供大家參考。具體如下:

這段程式碼示範了jQuery透過closest選擇器取得上一層的元素,然後修改其text()內容。

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> www.jb51.net </title>
<script type='text/javascript' src='jquery-1.9.1.js'></script>
<script type='text/javascript'>
//<![CDATA[
$(window).load(function(){
var address = $("#jb51").closest("div");
address.text('www.jb51.net')
});//]]>
</script>
</head>
<body>
<div id="website">
<div id="jb51"></div>
</div>
</body>
</html>

更多關於jquery選擇器相關內容有興趣的讀者可查看本站專題:《jquery選擇器用法總結

希望本文所述對大家的jQuery程式設計有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn