js innerHTML method to change div content

高洛峰
Release: 2017-02-13 14:10:30
Original
1915 people have browsed it

Changing Text InnerHTML
Every HTML element has an InnerHtml attribute that defines the HTML code and text that occurs between the element's opening and closing tags. By changing an element's innerHTML after some user interaction, you can make your web page more interactive.
However, using innerHTML requires some preparation if you want to be able to take advantage of it easily and reliably. First, you must give the ID card that you want to change. With the identifier in place, you will be able to use the getElementById function, which works in all browsers.
After you think about establishing the elements you can now manipulate the text. To get started, let's try changing the text to a bold marker.
Let’s take a look at how to use js innerHTML to change the div value.

<script type="text/javascript">
function changeText(){
document.getElementById(&#39;boldStuff&#39;).innerHTML = &#39;Fred Flinstone&#39;;
}
</script>
<p>Welcome to the site <b id=&#39;boldStuff&#39;>dude</b> </p>
<input type=&#39;button&#39; onclick=&#39;changeText()&#39; value=&#39;Change Text&#39;/>
Copy after login

For more js innerHTML methods to change div content, please pay attention to the PHP Chinese website for related articles!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!