Consider the following :-
$("#id").click(function(){
// how do i access $("#id") here: say i want to add a class to #id? without $("#id")
});
Consider the following :-
$("#id").click(function(){
// how do i access $("#id") here: say i want to add a class to #id? without $("#id")
});
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.
Read the JQuery documentation and you will find that you should use $(this)
.