Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
21
rated 0 times [  27] [ 6]  / answers: 1 / hits: 16757  / 13 Years ago, sat, july 16, 2011, 12:00:00

I have the following bit of code:



<div id=some_div style=border: solid 1px red; width:50px; height: 50px; 
onmouseover=(function(){$(this).css('background','green');})();></div>


The function gets run just fine but it doesn't seem to be able to find the 'this'.
How can I make it so that it will know to self-reference?



(Yes, jquery is referenced in my code)


More From » jquery

 Answers
199

I don't know if you want to be using an anonymous function there. I think



<div id=some_div style=border: solid 1px red; width:50px; height: 50px; 
onmouseover=$(this).css('background','green');></div>


will work.


[#91156] Thursday, July 14, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emileef

Total Points: 724
Total Questions: 108
Total Answers: 102

Location: Romania
Member since Sun, Dec 20, 2020
3 Years ago
;