jQuery prependTo() 方法

jQuery 教程 · 2019-03-27 16:42:58

实例

在每个 <p> 元素的开头插入 <span> 元素:

$("button").click(function(){ $("<span>Hello World!</span>").prependTo("p"); });

定义和用法

prependTo() 方法在被选元素的开头插入 HTML 元素。

提示:如需在被选元素的结尾插入 HTML 元素,请使用 appendTo() 方法。

语法

$(content).prependTo(selector)

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

注意:如果 content 是已存在的元素,它将从当前位置被移除,并在被选元素的开头被插入。
selector 必需。规定把内容预加到哪个元素上。

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

查看所有标签

Blog Design Solutions

Blog Design Solutions

Richard Rutter、Andy Budd、Simon Collison、Chris J Davis、Michael Heilemann、Phil Sherry、David Powers、John Oxton / friendsofED / 2006-2-16 / USD 39.99

Blogging has moved rapidly from being a craze to become a core feature of the Internetfrom individuals sharing their thoughts with the world via online diaries, through fans talking about their favori......一起来看看 《Blog Design Solutions》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具