`
jian0487
  • 浏览: 96194 次
  • 性别: Icon_minigender_1
  • 来自: 宁德
社区版块
存档分类
最新评论

jQuery:DOM部分之Manipulation 的使用

阅读更多

开始dom元素节点的添加删除等操作部分的函数学习

函数:after(content)

功能:在每个匹配的元素后面添加html内容

返回:jQuery对象

参数:content (<Content>): Content to insert after each target. 

例子:

Inserts some HTML after all paragraphs.



jQuery Code

$("p").after("<b>Hello</b>");

Before

<p>I would like to say: </p>

Result:

<p>I would like to say: </p><b>Hello</b>



Inserts an Element after all paragraphs.



jQuery Code

$("p").after( $("#foo")[0] );

Before

<b id="foo">Hello</b><p>I would like to say: </p>

Result:

<p>I would like to say: </p><b id="foo">Hello</b>



Inserts a jQuery object (similar to an Array of DOM Elements) after all paragraphs.



jQuery Code

$("p").after( $("b") );

Before

<b>Hello</b><p>I would like to say: </p>

Result:

<p>I would like to say: </p><b>Hello</b>


函数:append(content)

功能:在每个匹配元素之内添加content内容

返回:jQuery对象

参数:content (<Content>): Content to append to the target 

例子:

Appends some HTML to all paragraphs.



jQuery Code

$("p").append("<b>Hello</b>");

Before

<p>I would like to say: </p>

Result:

<p>I would like to say: <b>Hello</b></p>



Appends an Element to all paragraphs.



jQuery Code

$("p").append( $("#foo")[0] );

Before

<p>I would like to say: </p><b id="foo">Hello</b>

Result:

<p>I would like to say: <b id="foo">Hello</b></p>



Appends a jQuery object (similar to an Array of DOM Elements) to all paragraphs.



jQuery Code

$("p").append( $("b") );

Before

<p>I would like to say: </p><b>Hello</b>

Result:

<p>I would like to say: <b>Hello</b></p>


函数:appendTo(content)

功能:和append(content)类似,只不过是将前面匹配的元素添加到后面的元素内

返回:jQuery对象

参数:content (<Content>): Content to append to the selected element to. 

例子:

Appends all paragraphs to the element with the ID "foo"



jQuery Code

$("p").appendTo("#foo");

Before

<p>I would like to say: </p><div id="foo"></div>

Result:

<div id="foo"><p>I would like to say: </p></div>


函数:before(content)

功能:在匹配元素之前添加内容

返回:jQuery对象

参数:content (<Content>): Content to insert before each target. 

例子:

Inserts some HTML before all paragraphs.



jQuery Code

$("p").before("<b>Hello</b>");

Before

<p>I would like to say: </p>

Result:

<b>Hello</b><p>I would like to say: </p>



Inserts an Element before all paragraphs.



jQuery Code

$("p").before( $("#foo")[0] );

Before

<p>I would like to say: </p><b id="foo">Hello</b>

Result:

<b id="foo">Hello</b><p>I would like to say: </p>



Inserts a jQuery object (similar to an Array of DOM Elements) before all paragraphs.



jQuery Code

$("p").before( $("b") );

Before

<p>I would like to say: </p><b>Hello</b>

Result:

<b>Hello</b><p>I would like to say: </p>


函数:clone(deep)

功能:克隆dom元素

返回:jQuery对象

参数:deep (Boolean): (可选的) 是否克隆子节点及其自身

例子:

Clones all b elements (and selects the clones) and prepends them to all paragraphs.



jQuery Code

$("b").clone().prependTo("p");

Before

<b>Hello</b><p>, how are you?</p>

Result:

<b>Hello</b><p><b>Hello</b>, how are you?</p>
函数:empty()

功能:移除匹配元素的子节点

返回:jQuery对象

例子:

jQuery Code

$("p").empty()

Before

<p>Hello, <span>Person</span> <a href="#">and person</a></p>

Result:

[ <p></p>

函数:insertAfter(content)

功能:将匹配元素插入到content插入到之后

返回:jQuery对象

参数:Content to insert the selected element after

例子:

jQuery Code

$("p").insertAfter("#foo");

Before

<p>I would like to say: </p><div id="foo">Hello</div>

Result:

<div id="foo">Hello</div><p>I would like to say: </p>

[code]函数:insertBefore(content)
功能:将匹配元素插入到content插入到之前
返回:jQuery对象
参数:Content to insert the selected element before.
例子:
jQuery Code
$("p").insertBefore("#foo");
Before
<div id="foo">Hello</div><p>I would like to say: </p>
Result:
<p>I would like to say: <
分享到:
评论

相关推荐

    jQuery一个非常流行的操作Dom的JavaScript库

    尽管随着Vue.js、React、Angular等现代前端框架的兴起,jQuery在某些场景下的使用频率有所下降,但其依然是许多项目中的基础工具,尤其在处理DOM操作和动画效果时,jQuery依然表现出色。对于初学者和有经验的开发者...

    jQuery操作DOM解析

    **jQuery操作DOM解析** 在Web开发中,DOM(Document Object Model)是HTML或XML文档的结构化表示,它允许程序和脚本动态更新、添加、删除和改变元素。jQuery库简化了JavaScript对DOM的操作,提供了丰富的API来处理...

    JQuery:常用方法一览

    - **功能**:创建一个jQuery对象,包含DOM树中的元素。 - **示例**:`var $elems = $("p");` 3. **`$(function(){...})`**: - **功能**:文档加载完成时执行函数。 - **示例**:`$(function() { $("p").hide()...

    jquery.1.11.1.js

    DOM 操作(DOM Manipulation) jQuery 提供了丰富的 DOM 操作方法,包括添加、删除和替换元素。例如,`append()` 方法用于在元素内部添加内容,`remove()` 方法删除元素,`replaceWith()` 替换元素。 ### 4. 事件...

    jquery 常用 Dom操作

    ### jQuery 常用 DOM 操作详解 #### 属性(Attribute) 在 jQuery 中,属性操作主要包括获取、设置或修改元素的属性值。 1. **添加类(`addClass()`)** - **语法**:`$("selector").addClass("classname");` -...

    Jquery-Dom-Manipulation

    本项目 "Jquery-Dom-Manipulation" 可能包含了使用jQuery进行DOM操作的实例,通过查看源代码,你可以学习到如何将上述概念应用于实际项目中。通过实际操作和实践,你可以加深对jQuery的理解,提高网页动态交互的开发...

    JQUERY技术内幕:深入解析QUERY架构设计与实现原理 完整版 共两个包

    深入解析jquery架构设计与实现原理》首先通过...最后详细分析了功能模块的源码实现,包括:属性操作attributes、事件系统events、dom遍历traversing、dom操作manipulation、样式操作css、异步请求ajax、动画effects

    jquery Manipulation元素操作

    在Web开发中,jQuery库以其简洁、高效的API赢得了广大开发者喜爱,其中元素操作是jQuery的核心功能之一。这篇博客将深入探讨jQuery如何进行元素选择、操作和增强DOM(文档对象模型)的功能。 首先,jQuery提供了一...

    jquery实战:窗口效果

    3. **DOM操作(DOM Manipulation)**:jQuery允许我们方便地添加、删除和修改DOM元素。在窗口效果中,可能需要动态插入或更新窗口内容,或者改变窗口的显示状态。 4. **动画(Animations)**:jQuery的`.animate()`...

    jQuery跑马灯支持任何DOM元素

    在IT行业中,jQuery是一款广泛使用的JavaScript库,它极大地简化了DOM操作、事件处理、动画效果以及Ajax交互。本文将深入探讨“jQuery跑马灯支持任何DOM元素”这一主题,结合“跑马灯样式大全0101010101”的概念,...

    jquery:jquery原始码学习

    2. **DOM操作**:jQuery对DOM操作进行了封装,如`$(selector).html()`, `$(selector).append()`等,这些都是通过源码中的`Manipulation`模块实现的。这里涉及到元素的创建、插入、删除等,理解这部分源码有助于我们...

    jquery三个版本使用手册chm.rar

    **jQuery 是一个广泛使用的 JavaScript 库,它极大地简化了网页中的 JavaScript 编程,使得DOM操作、事件处理、动画设计以及Ajax交互变得更加便捷。本文将详细介绍压缩包文件中包含的三个jQuery版本的手册,帮助您...

    jqueryAPI jquery使用文档

    jQuery 的核心功能之一就是选择器,它借鉴了CSS的选择器语法,使得我们可以精准地选取DOM元素。例如: - `$("#id")`:通过ID选择元素。 - `$(".class")`:通过类名选择元素。 - `$("tag")`:通过标签名选择元素。 -...

    jquery使用的js文件

    《jQuery使用的JS文件详解》 在网页开发中,jQuery是一个不可或缺的JavaScript库,它极大地简化了JavaScript的DOM操作、事件处理、动画制作以及Ajax交互。本文将深入探讨jQuery的使用,以及如何引用和理解其中的JS...

    jquery:jquery源码分析

    jQuery 项目源码主要分为几个部分:core(核心)、selector(选择器引擎)、traversing(遍历)、manipulation(DOM 操作)、event(事件)、ajax(AJAX)等。随着版本的更新,jQuery 不断优化性能,增强功能,同时...

    jquery API 使用手册

    2. **DOM操作(DOM Manipulation)**:jQuery提供了方便的DOM操作方法,包括添加、删除和修改元素。例如,`append()`用于向元素内部追加内容,`remove()`移除元素,`html()`可以设置或获取元素的HTML内容。 3. **...

    jQuery1.8.3_中文使用手册

    2. **DOM操作(DOM Manipulation)**:jQuery提供了丰富的DOM操作方法,如`append()`用于在元素内部追加内容,`prepend()`在元素内部前置内容,`remove()`删除元素,`clone()`克隆元素,`html()`, `text()`, `val()`...

    jquery-1.11.3.js 、jquery-1.11.3.min.js 【官方jquery包 js】

    jQuery,作为一款广泛使用的JavaScript库,极大地简化了DOM操作、事件处理、动画制作以及Ajax交互等任务,深受前端开发者的喜爱。在这个主题中,我们将深入探讨jQuery 1.11.3版本的核心特性及其在实际开发中的应用。...

    jQuery:jQuery 源码分析

    jQuery 是一个广泛使用的 JavaScript 库,它极大地简化了 DOM 操作、事件处理、动画效果以及 AJAX 交互。jQuery 的流行在于其简洁的 API 和高效的代码实现,使得开发者能够用更少的代码实现更多的功能。 **一、...

    JQuery:jQuery基础

    2. **DOM操作(DOM Manipulation)** jQuery提供了丰富的API来操作DOM元素。例如,`$(selector).html()`用于获取或设置元素的HTML内容,`$(selector).append()`在元素末尾添加内容,`$(selector).prepend()`在元素...

Global site tag (gtag.js) - Google Analytics