本文实例讲述了jquery通过closest选择器修改上级元素的方法。分享给大家供大家参考。具体如下:
这段代码演示了jQuery通过closest选择器获取上一级的元素,然后修改其text()内容。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
<title> www.phpstudy.net </title>
<script type=\'text/javascript\' src=\'jquery-1.9.1.js\'></script>
<script type=\'text/javascript\'>
//<![CDATA[
$(window).load(function(){
var address = $(\"#phpstudy\").closest(\"div\");
address.text(\'www.phpstudy.net\')
});//]]>
</script>
</head>
<body>
<div id=\"website\">
<div id=\"phpstudy\"></div>
</div>
</body>
</html>
更多关于jquery选择器相关内容感兴趣的读者可查看本站专题:《jquery选择器用法总结》
希望本文所述对大家的jQuery程序设计有所帮助。
本文地址:https://www.stayed.cn/item/24601
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我