How to insert text in html code using javascript dynamically
HTML Tutorial » How to insert text in html code using javascript dynamically
The easiest way to insert text in html code, to modify the content of an HTML element is by using innerHTML property
<!DOCTYPE html>
<html>
<body>
<div id="test"><b>This text will be change to...</b></div>
<button onclick="changeIt()">Change....</button>
<script>
function changeIt() {
document.getElementById('test').innerHTML="<h2>Changed HTML code using JavaScript using innerHTML!!</h2>";
}
</script>
</body>
</html>
Related subjects:
How to put text in image HTML
How to insert text in HTML code using javascript dynamically
How to add text in HTML
How do I put text over an image in HTML?, How do I put text onto a picture?, How do I put text in the middle of an image in HTML?
Adding dynamically text in JavaScript - example
To get a reference of an element in JavaScript you need to call document.getElementById("my_div").
Your HTML string contains variables which are written as part of the string. Concatenation in JavaScript works with the plus sign (+). So This string will be:
<!DOCTYPE html>
<html>
<body><script type="text/javascript">
<input type="button" value="Add Input Ingredients" onClick="changeIt()">
function changeIt() {
var i = 1;
var j = 1;
document.getElementById("my_div").innerHTML = "<br><br><input type='text' name='mytext" + i + "' value='please Enter product'> <input type='text' name='mytet2" + j + "' value='please Enter quantity'>"
}
</script>
<div id="my_div"></div>
</body>
</html>
Tags: How can I add text to my website?, how to add text in html code, using javascript, How do I add dynamic text to a HTML tag, how to input text in html, how to insert text box in html, how to add text color in html, how to add hover text in html, how to put text in image html, how to put text in center htmlTags: how to insert text in html, html write text, writing text in html, add text
how to add hover text in html, how to put text in image html,
How to insert text in html code using javascript dynamically - html tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.