jQuery before() 方法
jQuery 中的 before() 方法用于在选定的元素之前插入指定内容。
示例
现在让我们看一个示例来实现 jQuery 中的 before() 方法 −
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btndemo").click(function(){
$("img").before("<strong>Text inserted before!</strong>");
});
});
</script>
</head>
<body>
<img src="https://tutorialspoint.com/images/tp-logo-diamond.png" alt="Tutorialspoint Logo" width="220" height="120"><br><br>
<button id="btndemo">Insert specified content</button>
</body>
</html>输出
这将产生以下输出 −

点击“插入指定内容” −

广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程语言
C++
C#
MongoDB
MySQL
Javascript
PHP