This block of JavaScript binds and then executes a custom event.
$("#a").on("stuff", "#d",
function() {
alert("hi");
});
$("#d").trigger("stuff");
With this HTML, the event should not trigger, but it does
<div id="a">
<div id="b"/>
<div id="c"/>
</div>
<div id="d">
</div>
However, with this HTML it works correctly. The event does not trigger.
<div id="a">
<div id="b"></div>
<div id="c"></div>
</div>
<div id="d">
</div>
The difference appears to be the use of XHTML.
This is posted in a couple of fiddles.
This one should not trigger the alert (in Chrome), but it does: http://jsfiddle.net/sZfs3/33/
This one works as expected: http://jsfiddle.net/sZfs3/34/
I've tried various permutations, using classes instead of id, for example, and get similar problems. The document is XHTML, and I've tried strict and transitional. Does anyone a know a reason that this would be a problem?