I have the following code that wires up the click event function to the submit button. I am aware that event.target and this are not always the same (as I understand it depends where the event was attached to and who actually fired it) but in this case the event was attached to the button and the button also fired it, so they should be the same. Or am I wrong?
modals.init = function () {
// wire up submit() function to the submit button
modals.config.$submitBtn.on('click', submit);
};
function submit(event) {
event.preventDefault();
var $this = $(this);
alert(event.target.id); // fine
alert($this.id); // undefined
}
It is
$this.attr("id")(jQuery element) orthis.id(DOM element)