Comparison of JavaScript frameworks (III)

Source: Internet
Author: User

DOM operations

Previously, you have seen that the JavaScript framework can easily obtain specific elements by using selector and DOM traversal. However, to change the content and appearance of specific elements on a webpage, You need to operate the DOM and apply the changes. Using pure JavaScript would be a heavy workload, but fortunately most JavaScript frameworks provide useful functions that can be easily done.

Suppose you have a box with the-box ID.

<Div id = "the-box"> Message goes here </div>
Using jQuery to change its text to "Message goes here", you can easily use it like this:

Certificate ('{the-box'{.html ('This is the new message! ');
In fact, you can use HTML code in a function, which can be parsed by a browser, for example:

Response ('{the-box'{.html ('this is the <strong> new </strong> message! ');
In this example, the content in the DIV element looks like this:

<Div id = "the-box"> This is the <strong> new </strong> message! '</Div>
Of course, you need to use special characters such as greater than or less than in the instance, rather than specifying special HTML Entity code. You can use the text function of jQuery instead:

$ ('# The-box'). text ('2017> 1000 ');
The code after the div element is updated is as follows:

<Div id = "the-box"> 300> 200 </div>
In the preceding example, the existing content is replaced with the new content. If you

What should I do if I only want to add some information to the text? Fortunately, jQuery provides the append function for this purpose.

$ ('# The-box'). append (', here goes message ');
After performing the preceding operations on the original div, the content in the div element looks like this:

<Div id = "the-box"> Message goes here, here goes message </div>
In addition to appending, You can append content to the front of the existing content instead of the back content. In addition, functions provided by jQuery can insert content into a given element, either before or after. There are also function replacement content, clearing content, removing elements, and cloning elements.

In addition to DOM operation functions, the JavaScript framework usually contains the style and class of several function operation elements. For example, if you have a table, you can highlight a row when you move the mouse over it. You can create a special class name hover. You can dynamically Add the class to a row. Using YUI, you can use the following code to determine whether the row has a hover class name.

If (row. hasClass ('hover ') row. removeClass ('hover'); else row. addClass ('hover ');
Similarly, most JavaScript frameworks have built-in functions for operating CSS.

Reprint address: http://www.denisdeng.com /? P = 712

Address: http://www.ibm.com/developerworks/web/library/wa-jsframeworks/index.html

Related Article

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.