Why is the onClick event triggered twice?

It is calling twice because the button is inside a span and span has onclick="alert('Boem')", hence when you trigger click on the button then it shows an alert and the same click event propagates to span and shows the alert once again.

You need to stop default behaviour of button using below code:

$(function(){
    $('#test1').click(function(e){e.preventDefault();}).click();
});

Demo

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)