jQuery - what exactly is 'this' referring to???

  • -->gm<--
  • Student
  • Student
  • User avatar
  • Joined: Mar 19, 2004
  • Posts: 68
  • Status: Offline

Post December 17th, 2008, 5:57 am

Hi everyone,

In the following code, what exactly is 'this' referring to???

Code: [ Select ]
$(document).ready(function(){
    $('li.headlink').hover(
        function() { $('ul', this).css('display', 'block'); },
        function() { $('ul', this).css('display', 'none'); });
});
  1. $(document).ready(function(){
  2.     $('li.headlink').hover(
  3.         function() { $('ul', this).css('display', 'block'); },
  4.         function() { $('ul', this).css('display', 'none'); });
  5. });


Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post December 17th, 2008, 5:57 am

  • Mas Sehguh
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Aug 07, 2004
  • Posts: 1853
  • Status: Offline

Post December 17th, 2008, 10:44 pm

Read the documentation: http://docs.jquery.com/Events/hover
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post December 18th, 2008, 12:59 am

The current <li> element out of the list of them obtained using $('li.headlink')
Strong with this one, the sudo is.
  • -->gm<--
  • Student
  • Student
  • User avatar
  • Joined: Mar 19, 2004
  • Posts: 68
  • Status: Offline

Post December 18th, 2008, 9:34 am

Thanks joebert,

@Mas Sehguh, FYI this != $(this)...
Have a read: http://docs.jquery.com/How_jQuery_Works

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 195 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.