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. Quote 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> Quote 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 Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.