Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change text on mouse over and change back on mouse out

I want to have a table that changes itself on mouse over and changes back to the original on mouse out. Here the best I can do:

<html>
<body>
<div id="line1">
    <table onmouseover="showMore()" border="1">
        <tr>  
            <td>this is sick</td>
        </tr>
    </table>
</div>

<script>
function showMore(){
    document.getElementById("line1").innerHTML = "<table border='1' onmouseout='showLess()'><tr><td>this is awesome</td></tr></table>";
}

function showLess(){
    document.getElementById("line1").innerHTML = "<table border='1' onmouseover='showMore()'><tr><td>this is sick</td></tr></table>";
}
</script>
</body>
</html>

However, sometimes when I move the mouse out, the content inside the still doesn't change back to the original. Is there a better way to do this?

Thanks!

like image 888
Thien Avatar asked Jan 14 '12 04:01

Thien


2 Answers

Well, you could certainly do it with CSS - http://jsfiddle.net/32HpH/

div#line1 span#a {
  display: inline;
}

div#line1:hover span#a {
  display: none;
}

div#line1 span#b {
  display: none;
}

div#line1:hover span#b {
  display: inline;
}
<div id="line1">
  <table border="1">
    <tr>
      <td>
        <span id="a">this is sick</span><span id="b">this is awesome</span>
      </td>
    </tr>
  </table>
</div>
like image 162
lambgrp425 Avatar answered Sep 30 '22 07:09

lambgrp425


I would do something like this:

<td 
   onmouseover="this.innerHTML='this is awsome';"
   onmouseout="this.innerHTML='this is sick';">
   this is sick
</td>

Here's a JSFiddle.

like image 21
guysigner Avatar answered Sep 30 '22 06:09

guysigner