Home > Web Front-end > JS Tutorial > Summary of jquery selector and attribute setting usage experience_jquery

Summary of jquery selector and attribute setting usage experience_jquery

WBOY
Release: 2016-05-16 17:23:16
Original
1371 people have browsed it

I am a novice and a fresh graduate. I have never used jquery before. I recently used jquery in a project. In the process of doing it, I took many detours and kept searching. Some usages are summarized for your reference:

The most basic selector syntax includes: id, class, label, attribute, which is consistent with css selector.

The ID selector should add # before the ID. For example, if you want to select a div element with the ID myDivID (

), you can write like this:

Copy code The code is as follows:

$("#myDivID");

D cannot be repeated, so the ID selector selects a jquery object.

The class selector should add a dot (.) before class. For example, if you want to select an input element with class myInputClass (), you can write like this:
Copy code The code is as follows:

$(".myInputClass");

class can be repeated, so the class selector can select one type of elements, that is, multiple elements, so jquery selects an array, and you can select each element by referring to the subscript: for example
Copy code The code is as follows:

for(var i = 0; i < $(". myInputClass").length; i ) {$(".myInputClass")[i];}

This way you can iterate out each element.

The tag selector can directly write the tag type. For example, if you want to select a paragraph p tag (

), you can write like this:
Copy code The code is as follows:

$("p");

The tag selector is also selected An array, select all p tag elements, you can also use the above method to iterate out all elements.

Attribute selectors should be preceded by square brackets ([]). For example, if you want to select elements with name="xxName", you can write like this:
Copy code The code is as follows:

$("[xxName]");

Select in this way, and the result will be the same An array because name can be repeated.

The ID selector can accurately select an element, but in development we may have to select a group of elements more. How can we accurately select the elements we want? In fact, there are several Selectors can be mixed:
Copy code The code is as follows:



< ;/span>







Summary of jquery selector and attribute setting usage experience_jquery
For example, we want to select an even number of text labels, that is: a text box that says even. We can choose like this:

First select this div, then select p, then select the text box with type="text", and finally select the even number of positions:
Copy code The code is as follows:

$("#attrValueTab p input[type='text']:even");

Combination selection is very useful in development. You can use the following method to select a checked button or checkbox element:
Copy code The code is as follows:

$("input[name='avDefValue_input']:checked");
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template