JavaScript dynamically changes page elements and javascript dynamic pages

Source: Internet
Author: User

JavaScript dynamically changes page elements and javascript dynamic pages

You can use JavaScript to dynamically change HTML elements.

Add elements to HTML

First, you need to create a tag, then add the corresponding content to the tag, and then add the created tag to the corresponding location.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Delete an element in HTML

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 




Javascript cannot dynamically change the id of an element in a webpage.

<Input type = 'text' id = "a">
<Input type = 'button 'onclick = "document. all ('A'). id = 'B'">
The button can only be pressed once, and it cannot be seen in the source file after the text ID is changed, but when you click the button again, it will show that there is no a object.

How does javascript modify the content of elements on a webpage?

Dynamic refers to the dynamic nature of data in webpages. For example, for news websites, data must be dynamic before it can be updated in real time.

Js changes the webpage element content to see what you want to change

For text, you must first put an object on the page, for example:
<Span id = mytext> </span>

// Js

Document. all ["mytext"]. innerText = "set text content ";

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.