I have the following html:
&
It is calling twice because button is inside a span and span has onclick="alert('Boem')"
, hence when you trigger click on button then it shows alert and same click event propagate to span and shows alert once again.
you need to stop default behaviour of button using below code :
$(function(){
$('#test1').click(function(e){e.preventDefault();}).click();
});
Demo