Matt Levesque
Matt Levesque

Reputation: 48

Javascript not working on IE

I have the follow code, which when hovering over an element, will show a div, and hide on mouseout. This works fine on every browser, except IE, here's my code;

// JavaScript Document

var baseopacity=0
function showtext(thetext){
    if (!document.getElementById)
    return
    textcontainerobj=document.getElementById("tabledescription")
    browserdetect=textcontainerobj.filters? "ie" : typeof textcontainerobj.style.MozOpacity=="string"? "mozilla" : ""
    instantset(baseopacity)
    document.getElementById("tabledescription").innerHTML=thetext
    highlighting=setInterval("gradualfade(textcontainerobj)",50)
}

function hidetext(){
    cleartimer()
    instantset(baseopacity)
}

function instantset(degree){
    if (browserdetect=="mozilla")
        textcontainerobj.style.MozOpacity=degree/100
    else if (browserdetect=="ie")
        textcontainerobj.filters.alpha.opacity=degree
    else if (document.getElementById && baseopacity==0)
        document.getElementById("tabledescription").innerHTML=""
}
function cleartimer(){
    if (window.highlighting) clearInterval(highlighting)
}
function gradualfade(cur2){
    if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
        cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.2, 0.99)
    else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
        cur2.filters.alpha.opacity+=20
    else if (window.highlighting)
        clearInterval(highlighting)
}
//<![CDATA[ 
$(window).load(function(){
    $(".tiptext").mouseover(function() {
        $(this).children(".description").show();
    }).mouseout(function() {
        $(this).children(".description").hide();
    });
});//]]>

Here is the HTML for one of the elements (each element's a picture) ;

<div id="one">
<div class="tiptext"><a href="http://mathremake.site40.net/"><img src="../images/web/1.png" height="180" width="300"/></a>
<div class="description"><font face="Arial, Helvetica, sans-serif"><u>Ascension Math Page</u></font><font size="2" face="Arial, Helvetica, sans-serif"><br>Ascension Collegiate's Mathematics department web page.</br></font></div>
</div>
</div>

And the CSS for the same element;

#one {
    top: 200px;
    position: absolute;
    width: 300px;
    position: absolute;
    left: 50%; 
    margin-left: -500px;
    } 

All help is appreciated, Thanks. :)

Upvotes: 0

Views: 186

Answers (2)

KoU_warch
KoU_warch

Reputation: 2150

You can try document ready to, also you can use .hover() function which can make things easier. Also i would recomend add a display:none css property to your .description class or make a new .hide class and add it.

Javascript

  $(function(){
     $(".tiptext").hover(function() {
         $(".description").show();
     },function() {
         $(".description").hide();
     });
  });​

CSS:

  .description{
     display:none;
  }

solution

Upvotes: 0

Ram
Ram

Reputation: 144659

IE has a problem with $(window).load(), you can try this:

$(window).bind('load', function(){
     ...
}); 

or:

$(document).ready(function() {
   $(".tiptext").hover(function() {
      $(this).find(".description").show();
   }, function() {
      $(this).find(".description").hide();
   });
});

Upvotes: 2

Related Questions