Home > Web Front-end > JS Tutorial > body text

Read jQuery Part 3 (Building Selectors)_jquery

WBOY
Release: 2016-05-16 18:05:52
Original
1036 people have browsed it

In order to describe the key points of each article, the sample code is the most streamlined. For example, the selector can only pass HTMLElement and id.

In this article we will enhance the selector. Based on the 2/8 principle, only the most commonly used ones will be implemented here.


1, obtained by id, this element is unique
$('#id')

2, obtained by className
$('.cls') Gets all elements in the document whose className is cls
$('.cls', el)
$('.cls', '#id')
$('span.cls') Gets all span elements with className cls in the document
$('span.cls', el) Gets the elements with className cls in the specified element, el is HTMLElement (not recommended)
$('span.cls', '#id') Get the element whose className is cls among the elements with the specified id

3, get
$(' through tagName span') Get all span elements in the document
$('span', el) Get the span element in the specified element, el is HTMLElement (not recommended)
$('span', '#id') Get the span element in the element with the specified id

4, get
$('[name]') through attribute Get the element with attribute name in the document
$( '[name]', el)
$('[name]', '#id')
$('[name=uname]') Get all elements with attribute name=uname in the document
$('[name=uname]', el)
$('[name=uname]', '#id')
$('input[name=uname]') Get all attribute names in the document =uname's input element
$('input[name=uname]', el)
$('input[name=uname]', '#id')

Example:

Copy code The code is as follows:





zchain test



aaa

bbb

ccc








Firebug output is as follows

Read jQuery Part 3 (Building Selectors)_jquery


http://demo.jb51.net/js/2011/zchain/zchain-0.3.js
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template