Questions to be noted by the jquery selector _jquery

Source: Internet
Author: User

Let's take a look at the code first, which is very simple, as follows

Copy Code code as follows:

<div id= "Div1" >
<span>111</span>
<span>222</span>
<span>333</span>
<button id= "Button1" >clear</button>
</div>

Copy Code code as follows:

$ (function () {
$ ("#button1"). Click (function () {
$ ("#div1 span"). HTML ("AAA");
});
});

$ ("#div1 span") gets an array of three objects

1. If you execute $ ("#div1 span"). HTML ("AAA"), all objects within the array will change. The following figure

2. If the $ ("#div1 span") is executed. html (), only the value of the first object in the array is taken

So if the selector gets an array, it's best to use each () when you want to operate on each element of the group.

There are other things to note.

A note selector containing a special symbol in the selector contains a ".", "#", "(" or "]" special characters, which are not included in the attribute value according to the requirements of the world's consortium, are occasionally encountered in an expression containing "#" and "." Such special characters, if the normal way to deal with the words will be wrong.

The way to resolve this type of error is to escape with an escape character.
<div id= "id#b" >bb</div>
<div id= "id[1]" >cc</div>

Can't write like this:
$ (' #id #b '); $ (' #id [1] ');
You should use the escape symbol:
$ (' #id \ #b '); Escape special Character "#"
$ (' #id \\[1\\] '); Escape special Characters "[]"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.