collecting hash only href on click

Benchmark created by rlemon on


Preparation HTML

<a href="#test" id="test">test</div>

Test runner

Ready to run.

Testing in
TestOps/sec
href.split
function iclick(event) {
event.preventDefault();
var hash = "#" + event.target.href.split("#")[0];
}
var a = document.getElementById("test");
a.addEventListener("click", iclick, false);
a.click();
ready
getAttribute
function iclick(event) {
event.preventDefault();
var hash = event.target.getAttribute("href");
}
var a = document.getElementById("test");
a.addEventListener("click", iclick, false);
a.click();
ready
href.substring
function iclick(event) {
event.preventDefault();
var h = event.target.href;
var hash = h.substring(h.lastIndexOf("#"), h.length);
}
var a = document.getElementById("test");
a.addEventListener("click", iclick, false);
a.click();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by rlemon on