3 ms·
There is one ambiguous case: If the data argument is a string, you must provide either a selector string or null so that the data isn’t mistaken as a selector.
by untog 15y ago
There is one ambiguous case: If the data argument is a string, you must provide either a selector string or null so that the data isn’t mistaken as a selector. Pass an object for data and you’ll never have to worry about special cases.
I'm being picky I know, but wouldn't it just be easier to use something like:
$("#div").on("click", {
selector: "span",
data: "blahblah",
handler: function()
});
Perhaps it's far too verbose, now that I've typed it out. But it just seems like it would do a good job of removing ambiguities like this.
- dmethvin 15y agoThe data feature isn't used that frequently, and when it is the best way to use it is by passing an object anyway. So although it's mentioned it is likely to be very uncommon.
- robin_reala 15y agoI use event data a lot, but I didn’t even realise you could pass a string.
- robryan 15y agoYeah, for bind and live I was under the impression that only an object would work from the docs.
- dmethvin 15y agoHaha, well it has always been documented to be an Object but turns out that there are a lot of people who don't read the documentation and pass strings or numbers. So rather than break their code in 1.7 we decided to document the fact that plain types can be used if you're careful.
- bergie 15y agoThe Create web editing interface uses event data a lot: https://github.com/bergie/create https://github.com/bergie/create