0

I was revising some concept in jquery then I found a simple code which I understood properly but there is "event" passed in that function and I didn't understand why is it passed because we could achieve that functionality without it.

var hiddenBox = $( "#banner-message" );
$( "#button-container button" ).on( "click", function( event ) {
  hiddenBox.show();
});

In above code I want to know why event is passed in this function? Also what better we can do with this. If possible please also provide an example.

Thanks

Pradhumn Sharma
  • 1,663
  • 2
  • 10
  • 19
  • 6
    Sometimes the parameter is essential, eg `event.preventDefault()`. If you don't use `event`, feel free to leave out the parameter – CertainPerformance Jan 11 '19 at 07:09
  • Yes I understand But I also want to know what this event is refering to? I mean is it refering to "#button-container button" or onClick event. – Pradhumn Sharma Jan 11 '19 at 07:12
  • 1
    https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events https://developer.mozilla.org/en-US/docs/Web/API/Event – CertainPerformance Jan 11 '19 at 07:13
  • 1
    This is not specific about jQuery, see the native `addEventListener` handler function as a reference, it also has the same parameter. – a--m Jan 11 '19 at 07:17

0 Answers0