I am learning jQuery and am looking to clarify what e.preventDefault() does. From what I have read it prevents the default behaviour of the event.
An example in my case would be that I have an anchor tag which rather than take me to a new page I want it to display a modal on my screen. So my jQuery looks like this
$(document).ready(function() {
$('#boxShow').click(function(e) {
e.preventDefault();
$("#light").fadeIn();
$('#fade').fadeIn();
});
Is the preventDefault() enabling me to perform a different event?
Apologies if this is a stupid question
It’s easy, it prevents the default event from happening. For example an
<a>element normally opens a link on click. In order to override that you will need to use this function.This is easier to read once you use
eventinstead of the acronyme.