jQuery.add()如何在jQuery中工作?
如果要将元素添加到现有元素组中,请使用add()方法。
示例
您可以尝试运行以下代码来学习如何使用jQuery.add()方法-
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("h1").add("p").css("background-color", "gray");
});
</script>
</head>
<body>
<h1>Nhooo</h1>
<p>Text Tutorials for free.</p>
<span>Video Tutorials for free.</span>
</body>
</html>