Web Analytics Made Easy -
StatCounter Add a mouse event - CodingForum

Announcement

Collapse
No announcement yet.

Add a mouse event

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Add a mouse event

    Having created a table using DOM how to I add a mouse event to the TD cell

    new_cell=document.createElement("TD")


    so I get

    <td onclick="do_this()"> </td>
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #2
    Code:
    new_cell=document.createElement("TD")
    new_cell.onclick=function(e){
        e=e||window.event;
        do_this();
    }
    liorean <[[email protected]]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

    Comment


    • #3
      Thanks Liorean that helps, but I still seem to be stuck

      I also need to pass two arguments in the function call so I end up with something like this.


      <td onclick="do_this('pic1',1)"> <img id="pic1" src""> </td>

      <td onclick="do_this('pic2',2)"> <img id="pic2" src""> </td>

      so the arguments are relative to the TD contents
      The silent one.

      The most dangerous thing in the world is an idea.
      The most dangerous person in the world is the one with an idea.

      Comment


      • #4
        Code:
        new_cell=document.createElement("TD")
        new_cell.onclick=function(e){
            e=e||window.event;
            do_this([i]id[/i], [i]number[/i]);
        }
        liorean <[[email protected]]>
        Articles: RegEx evolt wsabstract , Named Arguments
        Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
        Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

        Comment

        Working...
        X