0

Where is the documentation that explains why/how this works? jQuery interprets an undeclared variable as an id. I find this odd, and encountered by chance. How does it work?

HTML

<div id="wrapper"> <input id="a" value="click" type="button" /> </div> 

JS

$(wrapper).on("click", "#a", function(){ alert("test"); }); 

JSBIN

10
  • 2
    That's a quirk of JavaScript, not jQuery. Commented Nov 15, 2013 at 19:33
  • 3
    Here's a hint: it has nothing to do with jquery. Commented Nov 15, 2013 at 19:33
  • 1
    @zzzzBov: That's a quirk of Microsoft Internet Explorer, not JavaScript. :P Commented Nov 15, 2013 at 19:36
  • Related: stackoverflow.com/questions/19776533/… Commented Nov 15, 2013 at 19:37
  • @Amadan, all browsers do it, not just IE. It's a quirk of the language for backwards compatibility. Commented Nov 15, 2013 at 19:37

1 Answer 1

4

It doesn't. Javascript/the DOM does.

The id attribute is used to create a global variable that points to each element with an id.

This behaviour has been in Internet Explorer for years, and is now standardised in HTML5.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.