Address: http://www.qeefee.com/js/change-html-used-javascript
For more Javascript tutorials, visit> Javascript tutorials
Body:
Javascript is usually used to manipulate HTML and Change Webpage content!
Output content to the page
Javascript provides the document. write ('string') method to write content to the page:
<! DOCTYPE html>
You can copy this code to an html file and run it. When the page runs in a browser
At this time, we click the button and you will find that all the content on the page is overwritten:
The "culprit" of page content overwriting is the writeHtmlLater method called by the button onclick event. This method also writes a sentence to the page, but overwrites the whole page. Note the following:
Document. write () only outputs the written content to the document. If the document. write is executed after the document has been loaded, the entire HTML page will be overwritten.
Change HTML Tag content
We use JS not only to output some content to the document, but also to change the display of existing labels. The document tag access method is provided in Javascript: document. getElementById (). You can use this method to obtain the HTML tags you want to operate on and change their display:
<! DOCTYPE html>
Run this code and you will see the following page content:
After you click the change Span content button, you will find that the content of the span tag has changed:
This is because we have obtained this tag in the Code and re-assigned the value to its innerHTML attribute.
This article briefly introduces two ways to change the HTML content. In the subsequent sections, I will introduce more Javascript knowledge. Please stay tuned!