AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL
HTML Tutorial

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

Example: a simple code, change parameters
<!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:

Example:

<!DOCTYPE html>
<html>
<body>

<script type="text/javascript">
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>

<input type="button" value="Add Input Ingredients" onClick="changeIt()">
<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

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


HTML Img Background
HTML Image Link
HTML Image Size
HTML Text Style
HTML Text Align
HTML Text Size
HTML Text Color Style
HTML Text Color
HTML Table Color
HTML Table Row Colspan
HTML Table Width
HTML Table Style
HTML Table Border
HTML Table
HTML Font Face
HTML Font Size
HTML Font Color
HTML Headings
HTML div border color
HTML div class
HTML class container
HTML form action
HTML comment
HTML link new tab
HTML link underline
HTML link tag
HTML button action
HTML button onclick
HTML button link
HTML table style
HTML image
HTML colors
HTML div style
Text, paragraf in HTML
HTML Tags Attributes
HTML - Elements
HTML Introduction
Home HTML Tutorial
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Send forgot password by mail or message ...
PHP MySQL simple login system...
Check for duplicate username live or ema...
How to create simple search engine using...
Diseño de sitio web CSS Layout...
Diseño de caja flexible CSS3...
Botones en CSS...
ID y Clase, Diferencias entre Class e Id...
Esquina redondeada CSS...
Tamaño de caja css box-sizing: border-b...
Alineación CSS...
Altura y Anchura CSS...
Bordes CSS...
Margen CSS...
Relleno CSS...
Modelo de caja CSS...
Tablas CSS...
Listas CSS...
Enlaces CSS...
Texto CSS...