Here’s a JQuery function:
$("label[for='ch_c'], label[for='ch_ad']").click( function(){
if( $(this).hasClass('active') ){
$('#box').fadeIn(300);
} else {
$('#box').fadeOut(300);
}
});
I need (this) to refer to either of the two elements, so #box stays visible if either of them have class active. Currently, (this) only refers to the element that was actually clicked. Is there, in effect, a Jquery term for ‘either of these’?
In a
clickevent handler (and any other event handlers for that matter),thiswill always refer to the element that received the event. You could simply reuse the elements matched by your selector: