How to get the content in the middle of element tags in javascript _javascript tips

Source: Internet
Author: User
Tags html interpreter

Using AJAX, you can dynamically write to div and span tags by capturing server-side responses to information in Reponsetext or reponsexml, so that the page content is displayed without refreshing.

With JavaScript for dynamic modification, there are two ways to modify it:

1. One of the innerHTML attributes that uses HTML for each tag, using this property, as long as it provides a meaningful HTML snippet, the HTML interpreter can interpret the content and display it on the page, which is easier to use, Before each modification, you do not need to first remove the original content, but you can directly fill, fill the same time will be covered with the original content. This approach, though simple, is not yet a standard for the consortium, but the mainstream browsers such as Ie,firefox have been adopted.

2. the other is to create a text node node as a child of the div and span elements, in this way, the content to be displayed in Div and span is kept in text node so that the contents of the div and span elements are displayed by the text Node provided by. Note that each time you fill in the content, you need to delete the original text node, and then create a new text node and write the content. If not deleted, each time a fill operation is invoked, a new text node will be created, creating multiple text node nodes under the div and span elements, and each text node will display its own contents so that it does not overwrite the original content.

 

The above is a small compilation for everyone to get the content of the elements in the JavaScript in the middle of the implementation of the contents of the content, I hope that we support cloud-Habitat Community ~

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.