Trying to have jQuery access both the event.target and another element on click but receive the error:
Error: Syntax error, unrecognized expression: [object HTMLButtonElement],#element2
Selector code:
$(event.target+",#element2").closest("div").removeClass("alert-info").addClass("alert-success");
Any suggestions what I am doing wrong appreciated.
event.targetisn't a selector string, it's an element. You can wrap any element in a jQuery object:So you could perform your logic on both the element and the selector:
Or, two reduce a little repetition, you can use
.add()to combine jQuery objects into a set of objects: