jQuery User Manual Part 2 DOM Operation_jquery
我们以
herf() herf(val)
说明:对jQuery对象属性herf的操作。
例子:
未执行jQuery前
alert($("#test").href());
$("#test").href("2.html");
}
同理,jQuery还提供类似的其他方法,大家可以分别试验一下:
herf() herf(val) html() html(val) id() id (val) name() name (val) rel() rel (val)
src() src (val) title() title (val) val() val(val)
操作
after(html) 在匹配元素后插入一段html
$("#test").after("Hello");
}
after(elem) after(elems) 将指定对象elem或对象组elems插入到在匹配元素后

$("a").after($("#test"));
}

append(html)在匹配元素内部,且末尾插入指定html
$("#test").append("<b>Hellob>");
}
appendTo(expr) 与append(elem)相反

$("a"). appendTo ($("#test"));
}
clone() 复制一个jQuery对象
$("#test").clone().appendTo($("a"));
}
empty() 删除匹配对象的所有子节点





$("#test").empty();
}
insertAfter(expr) insertBefore(expr)
按照官方的解释和我的几个简单测试insertAfter(expr)相当于before(elem),insertBefore(expr)相当于after (elem)
prepend (html) prepend (elem) prepend (elems) 在匹配元素的内部且开始出插入
通过下面例子区分append(elem) appendTo(expr) prepend (elem)
<div>divdiv>
<div>divdiv>
p>
div
<p id="a">pp>
div>
<div>divdiv>
p>
remove() 删除匹配对象
注意区分empty(),empty()移出匹配对象的子节点,remove(),移出匹配对象
wrap(htm) 将匹配对象包含在给出的html代码内
$("p").wrap("");
}
wrap(elem) 将匹配对象包含在给出的对象内
<a href="#" onClick="jq()">jQuerya>
$("p").wrap( document.getElementById('content') );
}
遍历、组合
add(expr) 在原对象的基础上在附加符合指定表达式的jquery对象
<a href="#" onClick="jq()">jQuerya>
var f=$("p").add("span");
for(var i=0;i < $(f).size();i++){
alert($(f).eq(i).html());}
}
的对象,有两个,add("span")是在("p")的基础上加上匹配的对象,所有一共有3个,从上面的函数运行结果可以看到$("p").add("span")是3个对象的集合,分别是[ Hello Hello Again one one This is just a test. Hello Again And Again And Again one
add(el) 在匹配对象的基础上在附加指定的dom元素。
$("p").add(document.getElementById("a"));
add(els) 在匹配对象的基础上在附加指定的一组对象,els是一个数组。
<p>Hellop><p><span>Hello Againspan>p>
var f=$("p").add([document.getElementById("a"), document.getElementById("b")])
for(var i=0;i < $(f).size();i++){
alert($(f).eq(i).html());}
}
ancestors () 一依次以匹配结点的父节点的内容为对象,根节点除外(有点不好理解,看看下面例子就明白了)
<p>onep>
<span>
<u>twou>
span>
div>
var f= $("u").ancestors();
for(var i=0;i < $(f).size();i++){
alert($(f).eq(i).html());}
}
第一个对象是以的父节点的父节点(div)的内容为对象,[
一般一个文档还有和,依次类推下去。
ancestors (expr) 在ancestors()的基础上之取符合表达式的对象
如上各例子讲var f改为var f= $("u").ancestors(“div”),则只返回一个对象:
[
children() 返回匹配对象的子介点
<div id="ch">
<span>twospan>
div>
alert($("#ch").children().html());
}
children(expr) 返回匹配对象的子介点中符合表达式的节点
<span>twospan>
<span id="sp">threespan>
div>
alert($("#ch").children(“#sp”).html());
}
$("#ch").children(“#sp”)过滤得到[three ]
parent () parent (expr)取匹配对象父节点的。参照children帮助理解
contains(str) 返回匹配对象中包含字符串str的对象
<p>This is just a test.p><p>So is thisp>
alert($("p").contains("test").html());
}
end() 结束操作,返回到匹配元素清单上操作前的状态.
filter(expr) filter(exprs) 过滤现实匹配符合表达式的对象 exprs为数组,注意添加“[ ]”
alert($("p").filter(".selected").html())
}
find(expr) 在匹配的对象中继续查找符合表达式的对象
alert($("p").find("#a").html())
}
is(expr) 判断对象是否符合表达式,返回boolen值
alert($("#a").is("p"));
}
大家可以用$("#a").is("div"); ("#a").is("#a")多来测试一下
next() next(expr) 返回匹配对象剩余的兄弟节点
alert($("p").next().html());
alert($("p").next(".selected").html());
}
$("p").next(".selected) only returns [
prev () prev (expr) Refer to next to understand
not(el) not(expr) Remove the matching object from the jQuery object, el is the dom element, expr is the jQuery expression
<a href ="#" onclick="js()">jQuery a>
alert($("p").not(document.getElementById("a")).html());
alert($ ("p").not(“#a”).html());
}
siblings () siblings (expr) jquery Match other sibling-level objects in the object
<div>
<p id="a">two< /p>
div>
<a href="#" onclick ="js()">jQuery

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

This tutorial shows you how to integrate a custom Google Search API into your blog or website, offering a more refined search experience than standard WordPress theme search functions. It's surprisingly easy! You'll be able to restrict searches to y

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

This article series was rewritten in mid 2017 with up-to-date information and fresh examples. In this JSON example, we will look at how we can store simple values in a file using JSON format. Using the key-value pair notation, we can store any kind

Leverage jQuery for Effortless Web Page Layouts: 8 Essential Plugins jQuery simplifies web page layout significantly. This article highlights eight powerful jQuery plugins that streamline the process, particularly useful for manual website creation

Core points This in JavaScript usually refers to an object that "owns" the method, but it depends on how the function is called. When there is no current object, this refers to the global object. In a web browser, it is represented by window. When calling a function, this maintains the global object; but when calling an object constructor or any of its methods, this refers to an instance of the object. You can change the context of this using methods such as call(), apply(), and bind(). These methods call the function using the given this value and parameters. JavaScript is an excellent programming language. A few years ago, this sentence was

jQuery is a great JavaScript framework. However, as with any library, sometimes it’s necessary to get under the hood to discover what’s going on. Perhaps it’s because you’re tracing a bug or are just curious about how jQuery achieves a particular UI

This post compiles helpful cheat sheets, reference guides, quick recipes, and code snippets for Android, Blackberry, and iPhone app development. No developer should be without them! Touch Gesture Reference Guide (PDF) A valuable resource for desig
