Devima
Devima

Reputation: 1566

Why onchange fires before onclick in Chrome?

I would still take advantage of the expertise and availability of this community.
My question is: why if we have a code similar to

<input name="" type="checkbox"  onClick="first()" onChange="second()">
<script type="text/javascript">
function first(){
    console.log('first')
    }
function second(){
    console.log('second')
    }
</script>

in firefox onclick event fires before onchange while in chrome happens the opposite?
Thanks for your answers, maybe i have not explained in the best way
I know that using onMuseDown the problem is solved but i want to understand the reason for such behavior in Chrome with the onchange and onclick event

Upvotes: 4

Views: 2122

Answers (2)

Vincent
Vincent

Reputation: 630

One dirty solution might be to use onMouseDown instead of onClick.

But I'm also wondering why you really need both ;)

Upvotes: 1

Shijin TR
Shijin TR

Reputation: 7768

Because onChange is triggered due to onClick

Upvotes: 1

Related Questions