blackcell Posted October 6, 2008 Share Posted October 6, 2008 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. Link to comment https://forums.phpfreaks.com/topic/127228-populate-div-with-text-onclick/ Share on other sites More sharing options...
KevinM1 Posted October 6, 2008 Share Posted October 6, 2008 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> Link to comment https://forums.phpfreaks.com/topic/127228-populate-div-with-text-onclick/#findComment-658072 Share on other sites More sharing options...
blackcell Posted October 6, 2008 Author Share Posted October 6, 2008 Thanks Link to comment https://forums.phpfreaks.com/topic/127228-populate-div-with-text-onclick/#findComment-658355 Share on other sites More sharing options...
BillyBoB Posted October 6, 2008 Share Posted October 6, 2008 innerHTML isn't a proper way to fill in an object. innHTML is a string you cannot replace an object with a string in javascript. http://slayeroffice.com/articles/innerHTML_alternatives/ This is a great resource for what you are looking for. Link to comment https://forums.phpfreaks.com/topic/127228-populate-div-with-text-onclick/#findComment-658577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.