Reputation: 34006
Basically I have a form and when it's submited I add a class to blank fields to highlight them to be filled.
However when the user starts to fill an input or changes a "select" I want to remove this class.
This is what I'm trying, my problem is that I don't know how to select just the element that has been modified. How can I do this?
$("input, select").change(function(){
$('input').removeClass('highlight'); // Only affect modified element
});
Upvotes: 0
Views: 55
Reputation: 191809
Simply use $(this)
. jQuery methods will use that argument as the event element by default. If you only want to affect input
, then:
$(this).filter("input").removeClass(...)
Upvotes: 0
Reputation: 360026
Use this
. It's a very common jQuery idiom with all event (and many non-event) callbacks.
$("input, select").change(function(){
$(this).removeClass('highlight'); // Only affect modified element
});
http://api.jquery.com/bind/#event-handlers
The
handler
parameter takes a callback function, as shown above. Within the handler, the keywordthis
refers to the DOM element to which the handler is bound. To make use of the element in jQuery, it can be passed to the normal$()
function.
Upvotes: 1
Reputation: 94131
You could use $(this)
I guess:
$("input, select").change(function(){
$(this).removeClass('highlight'); // Only affect modified element
});
Upvotes: 1