The simple syntax of jquery is used

Source: Internet
Author: User

Statement: The material used in this column is written by the VIP students of the Kay Academy, who has the right to be anonymous and has the final right to interpret the article; The Edith Academy is designed to promote students to learn from each other on the basis of public notes.

The simple syntax of jquery is used

Because jquery wraps up objects and provides us with a range of methods, equivalent to the encapsulation in Java, if we want to do something about markup, we have to use the method provided by jquery, such as adding HTML code to the Div, previously using innerHTML, This is useless in jquery and requires the method HTML () provided by jquery. Here are some common ways to do this.

1. Event Registration: The event registration in jquery does not need to be added, as an example:

code example:

Operation Result:

Note: Here to notice the order of the script problem, if it is written before the body, then the event registration to write in the initialization method ready, this method is similar to onload, the body after parsing is finished running the code here, otherwise it will run the error, because the page parsing is from top to bottom, The button tag has not been parsed when parsing the code inside the script, and if it is written in the body, it is not required to be written in the Ready method, because the button tag is parsed.

2. About style: Add style with addclass (), delete style with Removeclass (), set the property value in the style with CSS ("Property name", "attribute value"), get the property value in the style with CSS ("attribute name"), example as follows: code example:

Operation Result:

3. About Tag Properties: Set the attribute value of the tag with attr ("Property name", "Property value"), get the Tagged attribute value attr ("Property name"), delete the tag's property value Removeattr ("Property name"). Examples are as follows:

code example:

Operation Result:

4. Control tag: The relevant method is as follows:

4.1 Append and delete tags:

4.2 Assignment methods: code examples for HTML () and text ():

By definition, HTML () is a fill code that encounters a marker symbol in the text that is parsed in the form of a corresponding tag, while text () is filled with text, and the marker symbol in the fill text is also treated as text rather than as a marker.

Conversely, the resulting value is also used with these two methods, examples are as follows:

From the above example, the HTML () obtained by including the page markup, text () is just text.

4.3 Get the value in the form Val (), this method is used only in form controls. Examples are as follows:

5. Showing and hiding: show () and hide (). The code examples are as follows:

In the example above, show (), Hide (), and toggle () can not pass in parameters, the incoming number indicates how long to show or hide the picture, there will be an animation effect, the time is in milliseconds. You can also pass in the string "fast" and so on, referring to the jquery API documentation.

The simple syntax of jquery is used

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.