How would I add a class to an object of a specific class upon click? The elements that should gain an extra class contain the “date” class.
$(".date").bind("click",addClass());
function addClass(){
//objectClicked.className+=""
}
I’m having trouble figuring out how to identify the exact element that was clicked.
In a jQuery event handler,
thisis bound to the source element of the event, so your can use$(this).addClass('yourClass');to add the new class to the clicked element.Also, watch out that you don’t invoke the
addClassfunction in the call tobind. That won’t work. You need to pass the function itself as I have.