DHTML operations to implement dynamic changes in Web page content

Source: Internet
Author: User
Tags object html tags implement insert
Dhtml|web| News | page

IE's DHTML object provides four read-write properties to dynamically manipulate the content of page elements: innertext, Outertext, InnerHTML, outerhtml.

Note two points:

1. The value of the Innertext,outertext property is rendered as plain text, even if it contains an HTML tag, and the innerHTML, outerHTML renders the text parsed by the HTML engine, It can react to the performance of HTML tags in attributes.

2. Assigning a value to an object's Outertext,outerhtml property (that is, a write operation) deletes the object.

The assignment of the above four attributes is only to replace the original object's text content, you want to specify the element-related position in the page add text content, you need to use the insertAdjacentHTML and insertAdjacentText methods. The form is as follows:

Object.insertadjacenttext (Swhere, Stext)
Object.insertadjacenthtml (Swhere, Stext)
Where Swhere represents the position of the inserted text relative to the HTML label, with the following four preset values:

Beforebegin,afterbegin,beforeend,afterend

The following points should be noted in use:

1. Both of these methods must be available after the entire document is loaded, or an error will occur.

2. insertAdjacentText can only insert plain text, insertadjacenthtml text inserted in HTML format

3. Insert a script with insertadjacenthtml, you must use the Defer property in the script element, otherwise a run-time error will occur

4. After insertadjacenthtml inserts an HTML element, all and other possible element collections are automatically updated to reflect dynamic changes. The Sourceindex properties of the subsequent elements of the page will change.

5. When you give an HTML tag that is not valid for the Inserthtml/outerhtml property, the method may have a run-time error. If the following code will be faulted:



In addition to the page content dynamic operation also need to note some of the following details:

1. Only the content displayed within the body of the document can be dynamically changed by the above properties and methods, the contents of the body object can be dynamically manipulated, but the body object itself cannot be replaced.

2. The above properties and methods cannot manipulate empty tags (HTML tags without content), such as input,img.

3. For table objects, only TD (Innerhtml/innertext) and table (Outerhmtl/outertext) objects can replace or insert content with certain properties, while other table objects, such as TR, Tbody cannot use these properties to change content.

Turn from: Dynamic Network production guide www.knowsky.com

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.