jQuery is not must for us--元素选取
来源:互联网 发布:个人顶级域名 编辑:程序博客网 时间:2024/05/17 22:47
元素选择
1 .ID
2 .class
3 .Tag
4 .Attributes
5 .伪类
6 .孩子选择器
7 .后代选择器
8 .排除选择器
9 .多组选择器
ID
jQuery
$("#myElement");
DOM API
document.getElementById("myElement");/*IE 8+*/document.querySelector('#myElement');
class
jQuery
$('.myElement');
DOM API
/*ie 9+*/document.getElementsByClassNmae('.myElement');/*ie 8+*/document.querySelectorAll('.myElement');
Tag
jQuery
$('div');
DOM API
document.getElementsByTagName('div');/**ie 8+/document.querySelectorAll('div');
Attribute[属性]
jQuery
$('[data-bar="red-bar"');
DOM API
/*ie 8+*/document.querySelectorAll('[data-bar="red-bar"');
伪类
jQuery
$('#myForm:invalid');
DOM API
//IE 10+document.querySelectorAll('#myForm:invalid')
孩子选择器
jQuery
$('#parent').children();
DOM API
/*会返回注释和文本节点*/document.getElementById('parent').childNodes/*ie 9+ 忽略注释和文本节点*/document.getElementById('parent').children;
选择包含ng-click属性的子节点
jQuery
$('#parent').children('[ng-click]');$('#parent > [ng-click]');
DOM API
document.querySelector('#parent > [ng-click]');
后代选择
jQuery
$("#parent a");
DOM API
document.querySelectorAll("#parent a");
排除选择
jQuery
$("div").not('.ignore');$('div:not(.ignore)');
DOM API
document.querySelectorAll('div:not(.ignore)');
多重选择
jQuery
$('DIV, A, SCRIPT');
DOM API
document.querySelectorAll('DIV, A, SCRIPT');
jQuery选择器模拟
window.$ = function(selector) { var selectorType = 'querySelectorAll'; if (selector.indexOf('#') === 0) { selectorType = 'getElementById'; selector = selector.substr(1, selector.length); } return document[selectorType](selector);};
1 0
- jQuery is not must for us--元素选取
- jQuery 选取元素
- jQuery 核心:选取元素
- jquery slibings选取同级其他元素
- Jquery元素选取及取值
- jquery选取自定义属性所在的元素
- jquery选取表单元素的方法
- Algorithm or maths is very important for us
- jQuery is not defined
- $ jQuery is not defined
- jQuery is not defined
- MATLAB报错:MTIMES is not fully supported for integer classes. At least one input must be scalar.
- JS/jQuery根据name来选取元素--测试过,可用
- JQuery选取非本身的同类名元素
- Why not us?
- RefernceError : jQuery is not define
- jquery live is not funciton
- jQuery ReferenceError: $ is not defined
- html去除html标签保留文本
- maven(二) 使用maven
- css 样式表
- 解决cookie过大问题
- jQuery使用prop设置checkbox全选、反选
- jQuery is not must for us--元素选取
- Java编程思想 之 线程简单应用
- 【手游】有杀气童话 美术资源加密分析
- 自定义checkbox
- Linux环境下为Tomcat安装APR
- 全面认识ldap
- MyEclipse配置Tomcat
- C语言编写小游戏——骑士飞行棋
- Android Studio 手动完成项目配置