Click on <a> link that doesn't jump to the top of the page
When user will click on the <a href="#x"> it won't jump to the top of the page. The secret is in the href value it should be value (id) that doesn't exists on the page e.g. href="#x"
<p>
text in paragraph
</p>
<a href="#x">LINK</a>
<p>
text in paragraph
</p>
<p>
text in paragraph
</p>
<p>
text in paragraph
</p>
<p>
text in paragraph
</p>
JavaScript
var docFrag = document.createDocumentFragment();
var firstP = document.querySelector("p");
for(var i = 0; i < 100; i++) {
var p = document.createElement("p");
p.innerText = (i + 1) + ")" + "inner text for the paragraph";
docFrag.appendChild(p);
}
document.body.insertBefore(docFrag, firstP);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.