4

I was messing around with jQuery and event handlers, when I noticed this:

enter image description here

That uses jQuery, and without it:

enter image description here

How does the popup get a bar saying jQuery? Do browsers have integrated jQuery support to detect that? Or is there some way to name event handlers? I want to have my event display some other text, like how jQuery does.

NOTE: I don't want to use jQuery, as I want to know how jQuery does it.

Universal Electricity
  • 775
  • 1
  • 12
  • 26
  • 1
    You can name *any* function. I don't understand the question. *edit* well I understand parts of it; yes some browser dev tools understand jQuery – Pointy Aug 23 '15 at 13:59

2 Answers2

1

I am not sure about what you are trying to do, but in Javascript you can always name functions

Example:

function myEventHandler(event) {
    alert('event handler');
}

myEventHandler is the name of the function.

Hope this helps a little, best, Carsten

1

You can have custom names for your events if you want. We can use the trigger function for the same purpose.

Suppose you want to raise myEvent on <div id="my_div">. We can simply

$("#my_div").trigger('myEvent');

and have a listener for the event:

$("#my_div").on('myEvent', function(event){
    //Event handler
});

You can find some good documentation here - https://learn.jquery.com/events/introduction-to-custom-events/

And this SO answer covers it thoroughly - Custom events in jQuery?

Community
  • 1
  • 1
Atishay Jain
  • 63
  • 1
  • 6