I am new to JS and basically I am trying to delve more into JS events and understand events and objects better. I came across a small difficulty that I would like to ask you kind people.
I wanted to know weather trigger('click') is the same as trigger({type : 'click'})
Now I wrote the below function to understand the difference and confirm if they are both the same:
<script>
$(document).ready(function(){
var call_it = function() {
setTimeout(function() {
$('#test').trigger({
type : 'click'
});
} , 1500 );
}
call_it();
$('#test').on('click' , function(){
console.log('button clicked');
});
});
</script>
Fiddle HERE
now when you replace :
$('#test').trigger({
type : 'click'
});
with:
$('#test').trigger('click' );
the click is still triggered, but I am still confused, HOW and WHY are they the same ?? HOW are they internally the same?
I know its a trick question , but I hope somebody can answer it.
Thank you.
Tenali.
Aucun commentaire:
Enregistrer un commentaire