html,content,website,programming,javascript, Change html element content using Javascript, Shopinson, Shopinson

Changing a content in a html element is a good one when it comes to creating a dynamic website and it is best achieved with javascript.

to change the content of html elements such as paragraph tag, italics tag, span tag and so on see the below example:

#EXAMPLE – DEMO

[sc name=”change html element content using javascript” ]
click the answer button and see changes

#CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Javascript Skills</title>
<script>
function myFunction() {
   document.getElementById("change").innerHTML = "<b>Answer:</b> Am fine.";
   document.getElementById("btn").innerHTML = "Answered";
}
</script>
</head>

<body>
<p id="change"><b>Question:</b> How is you?</p>
<button type="button" id="btn" onclick="myFunction()">Answer</button>
</body>
</html>

 

Javascript is a programming language that is of the high level language that can easily be used to change the content of html on click event.

 

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

shopinson-logo-32

©2020 Shopinson: complete guide to programming language

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account