0

I need to use browser event with namespace in the code. Is it necessary that the actual event name (for eg click) comes in the beginning of the event(click.mynamespace) or it can be anywhere in the event name with namespace.

In other words, will the event name "mynamespace.click" cause the event handler to trigger(on click of div) when used with on() method like :

$("div").on("mynamespace.click",...,...)
1

2 Answers 2

1

No, the event namespace has to follow the event name, In your case you are registering an handler for event mynamespace not click

Sign up to request clarification or add additional context in comments.

2 Comments

can you please point to the doc where this fact is mentioned.
@user2599052 I don't think it is mentioned in the documentation as such... but a simple look at source code makes it clear... see line number 4344 of code.jquery.com/jquery-1.11.2.js
-1

Why would you want to use namespace instead of an id or class?

With id:

$('#yourId').click(function(){
  yourCode
});

With class:

$('.yourClass').click(function(){
  yourCode
});

2 Comments

I am referring to event names with namespace and not the selectors.
I don't understand the idea of what you are trying to accomplish?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.