0

I've tryed to add some listeners to an existing div element

        //Prepare div
        $(this.div).css("z-index","256");
        $(this.div).attr("onmouseover",this.myname+".resize();");
        $(this.div).attr("onmousedown",this.myname+".resize();");
        $(this.div).attr("onmouseout","if("+this.myname+".sized)"+ this.myname+".resize();");

but in IE and Chrome the Event just doesn't get fired while it still gets added to the elements attributes. Firefox works as expected.

Does someone know whats wrong with it?

Thanks

1
  • You should really be using jquery's own evenhandling (.hover()) rather than adding to the attributes. Commented Feb 27, 2011 at 18:45

1 Answer 1

4

Do not set events as strings.
Instead, you should use jQuery's bind method:

var me = this;    //Inside the handlers, this is the element.

$(this.div).bind('mouseenter mousedown mouseleave',  function() { 
    me.resize(); 
});
Sign up to request clarification or add additional context in comments.

1 Comment

@Mereep - Also you don't have to create 4 instances of jQuery in order to do this. Use method chaining.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.