AF
Home
Tag
Submit Notes
Ask Anything
Login
Subscribe Us
A
ny
F
orum
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.
Follow @anyforumin
javascript-innerHTML: How to add content in a div tag by javascript?
As i know that innerHTML is used to replace the content of a div tag but i want to add content in a div tag(i.e. appending the content) .
javascript x 33
innerHTML x 1
Posted On :
2013-12-07 18:19:03.0
Garima Gupta
596
1295
60202
5
Answers
Yes, you can do it by div.innerHTML=div.innerHTML+"new stuff" . Let´s see the simple example, it has following steps:
1. First get the div tag by id in a variable.
2. now use div.innerHTML=div.innerHTML+"new stuff" .
******************* Example of Adding content in a div tag by javascript *******************
<script type="text/javascript">
function adding(a){
var div=document.getElementById("content");
div.innerHTML=div.innerHTML + " "+a;
}
</script>
<input type="button" value="hi" onclick="adding(this.value)" />
<input type="button" value="hello" onclick="adding(this.value)" />
<input type="button" value="bye" onclick="adding(this.value)" />
<div id="content"></div>
================================= Output =================================
Posted On :
2013-12-07 18:31:53
Satisfied :
1 Yes
0 No
Rishi Kumar
523
1882
50042
Reply This Thread
5
Post Answer
Please Login First to Post Answer:
Login
Answer:
anyforum.in