diff --git a/src/htmx.js b/src/htmx.js index 89fed0c3..ed5aaa72 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -925,7 +925,7 @@ return (function () { function shouldCancel(elt) { return elt.tagName === "FORM" || (matches(elt, 'input[type="submit"], button') && closest(elt, 'form') !== null) || - (elt.tagName === "A" && elt.href && elt.href.indexOf('#') !== 0); + (elt.tagName === "A" && elt.href && elt.getAttribute('href').indexOf('#') !== 0); } function ignoreBoostedAnchorCtrlClick(elt, evt) { diff --git a/test/core/internals.js b/test/core/internals.js index 1af2293c..e9513420 100644 --- a/test/core/internals.js +++ b/test/core/internals.js @@ -41,4 +41,24 @@ describe("Core htmx internals Tests", function() { chai.expect(htmx._("tokenizeString")("aa.aa")).to.be.deep.equal(['aa', '.', 'aa']); }) + it("tags respond correctly to shouldCancel", function() { + var anchorThatShouldCancel = make(""); + htmx._("shouldCancel")(anchorThatShouldCancel).should.equal(true); + + var anchorThatShouldNotCancel = make(""); + htmx._("shouldCancel")(anchorThatShouldNotCancel).should.equal(false); + + var form = make("
"); + htmx._("shouldCancel")(form).should.equal(true); + + var form = make(""); + var input = byId("i1"); + htmx._("shouldCancel")(input).should.equal(true); + + var form = make(""); + var button = byId("b1"); + htmx._("shouldCancel")(button).should.equal(true); + + }) + }); \ No newline at end of file