SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mouseover troubles with IE

    I create a "li" element using DOM. I add an "onmouseover" attribute, which calls a function that changes an image source and some text. Works just fine on Firefox and Opera, but IE acts as if the "onmouseover" were never there. Any suggestions?

    Also, the li items seem to have a width which extends to fill the whole page. I've tried "width: auto" in CSS, but haven't been able to make the width variable.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might be happening if you are using setAttribute to assign the onmouseover event handler. It also might happen if you are appending the LI to its parent before setting the event handler. If your code looks like this:

    Code:
    var ul = document.getElementById("myUL");
    var li = ul.appendChild(document.createElement("li"));
    li.appendChild(document.createTextNode("something"));
    li.setAttribute("onmouseover",function() {alert('mouseovered');});
    try changing it to:
    Code:
    var ul = document.getElementById("myUL");
    var li = document.createElement("li");
    li.appendChild(document.createTextNode("something"));
    li.onmouseover = function() {alert('mouseovered');};
    ul.appendChild(li);

  3. #3
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thank you very much, and one more thing...

    Thanks, that did the trick. Only thing remaining is, how can I define the adequate width for each of my li elements? If I put in a pixel value, they are no longer all flush with one another, so the mouseovers flicker (even though the padding and margins are 0 on both the parent 'ul' and the child 'li'). Besides, I want it to resize according to the individual text in each element.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •