Assiging actions dynamically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Justin Koivisto

    Assiging actions dynamically

    I am parsing some elements of an HTML document to add onmouseover and
    onmouseout actions to them dynamically. However, if they already have
    actions, I want to include them those as well...

    I can get the code inside the applied mouseover function with something
    like:

    if(typeof(obj.o nmouseover)=='f unction'){
    // make the function definition a string.
    funcOverDefn = "" + obj.onmouseover ;

    // find the positions of the openeing and closing
    // curly braces
    firstBrace = funcOverDefn.in dexOf('{');
    lastBrace = funcOverDefn.la stIndexOf('}');

    // get everything between the braces
    funcOverDefn=fu ncOverDefn.subs tring(firstBrac e+1,lastBrace);
    }

    Then if the element needs something applied (for instance, changing the
    display style), I use:

    obj.onmouseover =function(){
    // display the child element
    this.lastChild. style.display=" block";
    }

    However, I want to also apply the code found in the previously found
    funcOverDefn variable. Can this be accomplished?

    Any pointers/references greatly appreciated.

    TIA

    --
    Justin Koivisto - justin@koivi.co m

  • kevin.upchurch@gmail.com

    #2
    Re: Assiging actions dynamically

    I think this will work for you, but just try it. For each function your
    want on your mouse over, you can assign an event to it.

    obj.attachEvent ("onmouseover", nameofyourfunct ion1);

    obj.attachEvent ("onmouseover", nameofyourfunct ion2);

    Comment

    • Justin Koivisto

      #3
      Re: Assiging actions dynamically

      kevin.upchurch@ gmail.com wrote:
      [color=blue]
      > I think this will work for you, but just try it. For each function your
      > want on your mouse over, you can assign an event to it.
      >
      > obj.attachEvent ("onmouseover", nameofyourfunct ion1);
      >
      > obj.attachEvent ("onmouseover", nameofyourfunct ion2);
      >[/color]

      I should have waited a little before posting...

      I just stored the old function in a new property, and used the new one
      to call it:

      obj.oldonmouseo ver = obj.onmouseover ;
      obj.onmouseover =function(evt){
      if(this.oldonmo useover){
      this.oldonmouse over(evt);
      }
      this.lastChild. style.display=" block";
      }

      Seems like it never fails, post a message and find a way to do it... ;)

      I did try the addEventListene r, but that didn't work, then I realized I
      could do this instead.

      Thanks

      --
      Justin Koivisto - justin@koivi.co m

      Comment

      Working...