In js, I need to use :
$('.grid').on('submit','form', function (ev) {}
because i need to validate a html5 element into the form.
My problem is:
I have 2 submit button with 2 kind of "data". I need to get the trigger for using:
if(typeof [trigger].data('save') != 'undefined'){
}
it is the part of my current JS:
$('.grid').on('submit','form', function (ev) {
ev.preventDefault();
console.log(typeof $(this).data('save') );
if(typeof $(this).data('save') != 'undefined' && jQuery("form")[0].checkValidity()){
// do something
}
});
$(this) refere to the form element. I need that find the submit triggered button (not twice and not other submit button)
thanks
asked Apr 23, 2014 at 12:55
Jean-philippe Emond
1,6142 gold badges17 silver badges30 bronze badges
1 Answer 1
You should use event.target
The DOM element that initiated the event.
Change code to
if(typeof $(ev.target).data('save') != 'undefined'){
}
answered Apr 23, 2014 at 12:59
Satpal
134k13 gold badges168 silver badges171 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
$(ev.target).data('save')?