e.preventDefault()
is used to prevent the default action of some controls. For example, if you click a link, it will try to load its href
, if you click a submit button, it will try to submit the form. So, preventDefault
is used to prevent those actions.
If you don't want the submit to "interrupt", in other words, if you want to submit the form, remove the preventDefault
from your click event.
Now, second point, the click event is propagated 3 times. You have something like:
<div>
Div 1
<div>
Div 2
</div>
</div>
And you are binding the onclick method to every <div>
on the page. So, 3 divs, 3 onclicks.
If all divs are overlapped then when you click the inner one, you are clicking it's parent div too, and so on.
You can use stopPropagation()
if you don't want the event to propagate to deeper divs (think of it as "layers" one over each other).