jquery - Javascript closure scoping issue -


I am trying to find references to the cell and it looks blank. If I understand it correctly, then I should be able to reference the variable. correct?

  $ ('td [someAttr]'). Mousecenter (function (cell) {var timeoutId = setTimeout (function () {// should be variable cell?}, 1000);}); Mouse center (function (cell) {var timeoutId = setTimeout (function ()} //  

OR

  $ ('td [someAttr]') What should be the variable cell?}, 1000, cell);}); It was obvious, but due to this I asked this because the cell. Pejaks If you had, then undefined:  
 << / code>  > $ ( 'Td [someAttr]') Maussentr (function () {var cell = this; // var timed id = set timeout (function () {warning (cell.pageX); // cell.pageX will be zero) 1000);}); However, if you have:  
  $ ('td [someAttr]'). Mousecenter works well in the form of cell (cell.pageX); // The value will be the correct value in pagex.));  

The context of the event handler is set to the element that triggers the event You can get it this way:

  $ ('td [someAttr]'). Mousecenter (function () {var cell = this; var timed id = settimeout (function () {warning (Cell.tagName);}, 1000);});  

You may also want to wrap it as a jQuery object: var cell = $ (this); Update: The first argument is an event object, not the element element is set as a reference to the callback (i.e. it) and you can access the event object in the same way. That you were in your example:

  $ ('td [someAttr]'). Mausentr (function (event) {var cell = this; heroic Taimautaidi = timeout (function () {alert (Seltag_nam + '' + event. Pejaks);}, 1000);});  

Note that the "cell" element is also accessible as "event.target".


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -