ho-s
ho-s

Reputation: 89

addEventListener with 'submit' is not working, actually keep refreshing

im trying to do submit with enter in the form tag, but its not working
here is my code

document.querySelector('#button').addEventListener('submit',(e)=>{
    e.preventDefault()
    console.log('it works')
})
<ul>
    <li>
        <div>
            <form>
                <input></input>
                <button type="submit" id='button'></button>
            </form>
        </div>
    </li>
</ul>

Upvotes: 0

Views: 1336

Answers (1)

Quentin
Quentin

Reputation: 943214

Submit events fire on form elements, not button elements.

You're listening for the event in the wrong place.

Upvotes: 3

Related Questions