Jump to content

Populate div with text onclick


blackcell

Recommended Posts

I have been trying for some time to figure out how populate text into a div by onclick. I can change an image onclick but not text filling.

Any help would be greatly appreciated.

 

<script type="text/javascript">
   window.onload = function()
   {
      var myTrigger = document.getElementById('trigger');
      var myText = document.getElementById('text');

      myTrigger.onclick = function()
      {
         myText.innerHTML = "I just got added to this div!";
      }
   }
</script>

<!-- ... -->

<a href="#" id="trigger">Click me to add text below!</a>

<div id="text">
</div>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.