tags:

views:

33

answers:

3

Consider the following :-

$("#id").click(function(){
// how do i access $("#id") here: say i want to add a class to #id? without $("#id")
});
+4  A: 

You can use the this context to access the item selected.

$("#id").click(function() {
  $(this).addClass("blah");
});

Alternatively, each event handler is also passed an event and you can derive the information from that:

$("#id").click(function(evt) {
  $(evt.target).addClass("blah");
});

See the jQuery Event object.

I generally favour the approach using this however.

cletus
Bah. By 10 seconds. :p
nlaq
A: 
$(this).addClass("class");
nlaq
A: 

Read the JQuery documentation and you will find that you should use $(this).

Deniz Dogan