It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming HTML Forum

Mouse-hover text effect

Mouse-hover text effect

Postby virusys on Mon Mar 12, 2007 6:13 pm

Hi, I'm not sure if this can be done with HTML, but I'm trying to make something that adds extra text when the mouse hovers over a certain area of text.

For example,

I would like something to happen like this:

This is a sentence.

and hovering over the word "sentence" would print out

This is a sentence. This is another sentence.

and so on...

basically whenever the mouse hovers over a specific point I want text to be appended.

Can anyone help me with this?

Thanks,

Virusys[/b]
virusys
 
Posts: 2
Joined: Mon Mar 12, 2007 6:08 pm

Postby mwa103 on Mon Mar 12, 2007 9:16 pm

After some googling, I've put together something you may be able to use. It will need a little bit of work, but the basic idea is there.

Code: Select all
<html>
<head>
<title>HOVER</title>
<script type="text/javascript">
<!--

function addInfo(myDiv)
{
    var text = "This is another <a href=# onMouseOver=\"addInfo('infoDiv')\">sentence. </a>";
    var ni = document.getElementById(myDiv);
    var numi = document.getElementById('theValue');
    var num = (document.getElementById("theValue").value -1)+ 2;
    numi.value = num;
    var divIdName = "my"+num+"Div";
    var newdiv = document.createElement('div');
    newdiv.setAttribute("id",divIdName);
    newdiv.setAttribute("style", "float: left;");
    newdiv.innerHTML = text;
    ni.appendChild(newdiv);
}

function removeEvent(divNum)
{
    var d = document.getElementById('myDiv');
    var olddiv = document.getElementById(divNum);
    d.removeChild(olddiv);
}

//-->
</script>
</head>
<body>
    <input type=hidden name=theValue id=theValue value=0>
    <div id='infoDiv'>
        <div id=my0Div style='float: left'>This is a <a href=# onMouseOver="addInfo('infoDiv')">sentence. </a></div>
    </div>
</body>
</html>


This is the site where I found the script: http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/

Hope this helps.
-Mike
mwa103
100+ Club
 
Posts: 206
Joined: Mon Mar 07, 2005 10:55 pm

Postby virusys on Mon Mar 12, 2007 10:49 pm

Awesome! Thanks so much.
virusys
 
Posts: 2
Joined: Mon Mar 12, 2007 6:08 pm


Who is online

Users browsing this forum: No registered users and 5 guests