Announcement

Collapse
No announcement yet.

Access "this" in events assigned by jQuery

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

    Access "this" in events assigned by jQuery

    Hi,

    I am creating a simple class to assign mouse in and out events to "a" tag, using jQuery.
    public class Test
        {
            public Test()
            {
                jQuery.Select("a").Hover(min, mout);
            }
    
            public void mout()
            {
               //some code
            }
    
            public void min()
            {
                //some code
            }
        }
    generated code for hover method looks like :
    $("a").hover(Bridge.fn.bind(this, this.min), Bridge.fn.bind(this, this.mout));
    which bind "this" variable to the class and prevent me to access the "a" tag in events.
    is there any way I can solve this issue (either be able to get the sender, or remove Bridge.fn.bind.

    Thanks.
    Last edited by mahyar; 2016-08-19 @ 06:37 AM. Reason: add tags

    #2
    Please use jQuery.This which will be translated to $(this) or Script.This<T>() which will be translated to this.
    Last edited by geoffrey.mcgill; 2016-08-19 @ 07:05 PM.

    Comment


      #3
      Thanks for your reply, the issue was the Bridge.fn.bind(this, this.min), which bind this to the assigned event.
      I found out, if I define my methods as static method, it solves the issue, and generated code not use any Bridge binding.

      Comment

      Working...
      X