Ajax combat: Using JavaScript to manipulate DOM

Source: Internet
Author: User
Tags html page new set

In any application, we need to change the user interface during the user's use, and provide feedback to the user for the operation and completion of the process. The feedback includes modifying a single element's label or color, ejecting a temporary dialog box, replacing most of the screen content with a new set of UI components, and so on. The most common way to date is to construct a DOM tree (in other words, to write an HTML page) by providing a declarative HTML to the browser.

The documentation we showed in listing 2-2 and figure 2-3 is a bit too big and complex, or a small step to start DOM operations. Let's say we want to show friendly greetings to the user. When the page first loads, we do not know his name, so we want to modify the structure of the page later to add the name of the user, through the programmatic operation of the DOM node can do this thing. Listing 2-3 shows the initial HTML markup for this simple page.

Code listings 2-3 Ajax "Hello" page

We added two references to external resources: CSS and files that contain JavaScript code. We have also declared an empty element with an ID, and can later add more elements to it programmatically.

Let's take a look at the resources that are linked. By modifying the fonts and colors, the style sheet defines some simple styles for distinguishing between categories of entries in the list (code listing 2-4).

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.