AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
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 ?.



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
profile Garima Gupta - anyforum.in Garima Gupta
596129560202
up-rate
5
down-rate

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
profile Rishi Kumar - anyforum.in Rishi Kumar
523188250042
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in