Jump to content

Hover Event - Output/Replace Html


Aucun

Recommended Posts

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

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 by Aucun
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...