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

  • -->gm<--
  • Student
  • Student
  • User avatar
  • Posts: 68

Post 3+ Months Ago

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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Mas Sehguh
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1853

Post 3+ Months Ago

Read the documentation: http://docs.jquery.com/Events/hover
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

The current <li> element out of the list of them obtained using $('li.headlink')
  • -->gm<--
  • Student
  • Student
  • User avatar
  • Posts: 68

Post 3+ Months Ago

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 148 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.