R
R
Roman Jolud2018-07-14 22:49:14
JavaScript
Roman Jolud, 2018-07-14 22:49:14

Why write e.preventDefault()?

Wrote code for dragging an element from one div to another , but didn't understand why write e.preventDefault() (wrote from the tutorial).
Here are the lines of code with e.preventDefault():

function dragOver(e){
    e.preventDefault(); 
}

Here's another:
function dragEnter(e){
    e.preventDefault();
    this.className += ' hovered'; 
}

Here is what hovered does in CSS:
{
    background: #f4f4f4;
    border-style: dashed;
    background-color: salmon;
}

You need to understand why write e.preventDefault() in these functions
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-07-14
@romanjolud

Event.preventDefault()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question