javascript/DHTML setAttribute onmouseover run function pass variable IE

Posted on 2007-10-12
Last Modified: 2013-11-19
The following works perfectly in FF but not in IE,



function runstuff(tbodyID){
      var txt, l, td, tr, tbody
      tbody = document.getElementById(tbodyID)
  var frag = document.createDocumentFragment();

  for (var i = 1; i < 4; i++){
        tr = document.createElement("tr");
        for (var k = 1; k < 4; k++){
              var l = i + "-" + k
              td = document.createElement("td");
              td.setAttribute("onmouseover", "StartToolTip('" + l + "')");
              txt = document.createTextNode(l);

function StartToolTip(mytip){

<body onload="runstuff('maindata')">
            <tbody id="maindata"></tbody>

i've found plenty of questions about this, but cannot make any of the solutions work in both browsers.

Many thanks
Question by:jondanger
    LVL 28

    Expert Comment

    Hi, try to replace this line

      td.setAttribute("onmouseover", "StartToolTip('" + l + "')");

    with this one

      td.onmouseover= function() { StartToolTip(l); };
    LVL 28

    Expert Comment

    No, disregard my comment, it will not work correctly.
    LVL 8

    Accepted Solution

    td.onmouseover = new Function("StartToolTip(\"" + l + "\");");

    Author Comment

    Tname: i thought it had worked! the alert box appears in IE but the value was 3-3 for every cell. thanks for trying.

    malfunction84: brilliant, i've been at this for hours :)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Shoutout to Emily Plummer ( for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
    Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now