jQuery in action 3rd - Operating on a jQuery collection
1、创建新 DOM 元素
$('<div>Hello</div>');
$('<img>', {
src: 'images/little.bear.png',
alt: 'Little Bear',
title: 'I woof in yor general direction',
click: function() {
alert($(this).attr('title'));
}
}).appendTo('body');
2、操作 jQuery collection 对象的方法
get([index])
示例:$('img[alt]').get(0)
eq(index)
示例:$('img[alt]').eq(2)
first()
示例:$('img[alt]').first()
last()
示例:$('img[alt]').last()
toArray()
示例:$('img[alt]').toArray()
index()
示例:$(#main-menu > li').index($('#blog-link'));
父子、祖先、子孙关系函数
add()
not()
示例,
$('div').not(function(index) {
// 注意,此处的 this 是一个 DOMElement 对象,而不是 jQuery 对象
return $(this).children().length > 2;
});
filter()
示例,
$('td').filter(function() {
// 注意,此处的 this 是一个 DOMElement 对象,而不是 jQuery 对象
return this.innerHTML.match(/^\d+$/);
});
$('img').filter('[title*="dog"]').addClass('red-border');
slice()
has()
map()
示例,
$('div').map(function() {
// 注意,此处的 this 是一个 DOMElement 对象,而不是 jQuery 对象
return this.id;
});
each()
示例,
$('img').each(function(index) {
// 注意,此处的 this 是一个 DOMElement 对象,而不是 jQuery 对象
return this.id;
});
is()
end()
addBack()
jQuery in action 3rd - Operating on a jQuery collection的更多相关文章
- jQuery in action 3rd - Introducing jQuery
2014 年 10 月, jQuery Foundation 的总裁 Dave Methvin 发布了一篇博客(http://blog.jquery.com/2014/10/29/jquery-3-0 ...
- jQuery in action 3rd - Working with properties, attributes, and data
properties properties 是 JavaScript 对象内在的属性,可以进行动态创建,修改等操作. attributes 指的是 DOM 元素标记出来的属性,不是实例对象的属性. 例 ...
- jQuery in action 3rd - Selecting elements
jQuery(selector) / $(selector) selector 选择器有多种形式,下面是 #ID,.class,element jQuery 支持的 CSS 层级关系选择器 jQuer ...
- JQuery IN ACTION读书笔记之一: JQuery选择器
本章关注两个通过$()使用的常用功能: 通过选择器选择DOM元素,创建新DOM元素. 2.1 选择操作元素 JQuery采用了CSS的语法,而CSS的语法你可能已经很熟悉了.当然,JQuery也做了扩 ...
- jQuery Tools:Web开发必备的 jQuery UI 库
基本介绍 jQuery Tools 是基于 jQuery 开发的网站界面库,包含网站最常用的Tabs(选项卡).Tooltip(信息提示).Overlay(遮罩.弹窗).Scrollable(滚动控制 ...
- JQuery制作网页——第五章 初识 jQuery
1.jQuery简介: ● jQuery由美国人John Resig于2006年创建 ● jQuery是目前最流行的JavaScript程序库,它是对JavaScript对象和函数的封装 ● 它的设计 ...
- 《锋利的JQuery》读书要点笔记1——认识JQuery&&选择器
<锋利的jQuery>源码下载,包括了这本书中全部代码以及用到的CSS文件 第一章 认识jQuery jQuery是个Js库.首先该明确的一点是:在jQuery库中$就是jQuery的一个 ...
- jquery的$.extend、$.fn.extend、 jQuery.extend( target, object1, [objectN])作用及区别
jQuery为开发插件提拱了两个方法,分别是: jQuery.fn.extend(); jQuery.extend(); 虽然 javascript 没有明确的类的概念,但是用类来理解它,会更方便. ...
- 【jQuery基础学习】08 编写自定义jQuery插件
目的:虽然jQuery各种各样的功能已经很完善了,但是我们还是要学会自己去编写插件.这样我们可以去封装一些项目中经常用到的专属的代码,以便后期维护和提高开发效率. jQuery插件的类型: 封装对象方 ...
随机推荐
- Aquarium Cycling
http://www.fishyou.com/aquarium-cycling.php Aquarium Cycling Aquarium cycling actually refers to the ...
- Chap5: question 35 - 37
35. 第一个只出现一次的字符 char firtNotRepeat(char *s) { if(s == NULL) return 0; int i = 0; while(s[i] != '\0') ...
- 25. Valid Palindrome
Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric char ...
- 【VB.NET】文本框快捷键支持
我们知道VB.NET中的文本框是不支持Ctrl+A的快捷键的. 如果让它支持呢? Private Sub txtSQL_KeyDown(ByVal sender As Object, ByVal e ...
- 伪静态URLRewrite学习笔记
UrlRewrite: UrlRewrite就是我们通常说的地址重写,用户得到的全部都是经过处理后的URL地址,类似于Apache的mod_rewrite.将我们的动态网页地址转化为静态的地址,如ht ...
- No.014 Longest Common Prefix
14. Longest Common Prefix Total Accepted: 112204 Total Submissions: 385070 Difficulty: Easy Write a ...
- C++学习基础九——继承
1.不同于Java中通过extends实现继承,C++是通过:实现的. 2.C++中同样包含public,private,protected三个关键字: public关键字表示在任意其他类中可调用该成 ...
- zabbix3.0.4监控mysql主从同步
zabbix3.0.4监控mysql主从同步 1.监控mysql主从同步原理: 执行一个命令 mysql -u zabbix -pzabbix -e 'show slave status\G' 我们在 ...
- 使用linux的nc来进行文件的传输
NAME nc - arbitrary TCP and UDP connections and listensSYNOPSIS nc [-46DdhklnrStUuvz] [-i interv ...
- ubuntu 14.04 更新 gcc/g++ 4.9.2
ubuntu 14.04 更新 gcc/g++ 4.9.2 最近看到c++11非常的好用,尤其是自带了regex,于是稍微学了一下c++11的新特性.可是我在编译一个regex程序是却发现稍微复杂一点 ...