jQuery before() 方法

jQuery 教程 · 2019-03-27 12:14:16

实例

在每个 <p> 元素前插入内容:

$("button").click(function(){ $("p").before("<p>Hello world!</p>"); });

定义和用法

before() 方法在被选元素之前插入指定的内容。

提示:如需在被选元素后插入内容,请使用 after() 方法。

语法

$(selector).before(content,function(index))

参数 描述
content 规定要插入的内容(可包含 HTML 标签)。

可能的值:

  • HTML 元素
  • jQuery 对象
  • DOM 元素
function(index) 可选。规定返回待插入内容的函数。
  • index - 返回集合中元素的 index 位置。

点击查看所有 jQuery 教程 文章: https://codercto.com/courses/l/35.html

查看所有标签

The Cult of the Amateur

The Cult of the Amateur

Andrew Keen / Crown Business / 2007-6-5 / USD 22.95

Amateur hour has arrived, and the audience is running the show In a hard-hitting and provocative polemic, Silicon Valley insider and pundit Andrew Keen exposes the grave consequences of today’s......一起来看看 《The Cult of the Amateur》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

html转js在线工具
html转js在线工具

html转js在线工具