Aucun Posted October 16, 2013 Share Posted October 16, 2013 Hello, I'm very new to Javascript and I have a few questions regarding it's use with HTML. I'm trying to change HTML code for when a <div> tag is hovered over (the div is a "button" of sorts). I need the HTML in a specific <div> tag to change when the button is hovered over, and then remain until another button is hovered over. I've done some searching and found a few things that will probably work I'm just not sure how to put them together properly. I found this example that shows text being changed: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><head><title>I can change text =) </title><style type=text/css>div{font-family: Georgia}</style></head><body><script type=text/javascript>function changetext(){var textchange2 = "This is the new me " ;var id = document.getElementById("DP");id.innerHTML=textchange2;}</script><div id="DP" onmouseover="changetext();">Lets say this is text 1</div></body></html> I'm not sure how to apply HTML as the "text", and if it replaces or adds to what is already inside the <div> tag. The button is not the same <div> tag that needs to be changed. Link to comment Share on other sites More sharing options...
niche Posted October 16, 2013 Share Posted October 16, 2013 According to your code it changes it. Link to comment Share on other sites More sharing options...
Aucun Posted October 17, 2013 Author Share Posted October 17, 2013 Does anything need to be changed to replace HTML in the div tag then? Link to comment Share on other sites More sharing options...
Don E Posted October 17, 2013 Share Posted October 17, 2013 When you say replace the HTML inside the div tag, do you mean the text inside it? If so, it does change when you hover over it as niche mentioned. Link to comment Share on other sites More sharing options...
Aucun Posted October 17, 2013 Author Share Posted October 17, 2013 (edited) When you say replace the HTML inside the div tag, do you mean the text inside it? If so, it does change when you hover over it as niche mentioned. Here is an example of what I want to do: <html><body><div id="name"><p>dsgsdfgs</p></div></body></html> Change it to say: <html><body><div id="name"><h1>asfasfasf</h1></div></body></html> Edited October 17, 2013 by Aucun Link to comment Share on other sites More sharing options...
thescientist Posted October 17, 2013 Share Posted October 17, 2013 why not just try it? document.getElementById('name').innerHTML = '<h1>asfasfasf</h1>'; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now