When I click cancel the form submit(( Why? I tried add to "". Everything is okey. But I need confirmation only when tr backgorund color is yellow. This way it doesn't cancel sumbmition...
$('#cart_form').submit(function() {
$("tr").each(function(indx, element)
{
if (element.style.backgroundColor=="rgb(255, 255, 179)"){
var c = confirm("Are u sure?");
return c;
}
});
});
You are return
ing from the function you pass to each()
. See the documentation which says:
You can stop the loop from within the callback function by returning false.
The loop, not the form submission!
You need to return from the function you pass to submit()
(or, better, capture the first argument given to that function (the event object) and call preventDefault()
on it).