Last active
February 4, 2016 15:17
-
-
Save nikoloza/43e025c0c8ce2cbdf9c4 to your computer and use it in GitHub Desktop.
Making 'href' for any element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- The original idea came from https://github.com/nathanford/data-href --> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<section> | |
<p data-href="#/paragraph/url/"> | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod | |
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim | |
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea | |
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate | |
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint | |
occaecat cupidatat non proident, sunt in culpa qui officia deserunt | |
mollit <a href="#/a/url">anim id est laborum</a>. | |
</p> | |
</section> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script> | |
<script type="text/javascript"> | |
$(document).on('click', '[data-href]', function(e){ | |
if(e.target.nodeName !== "A") window.location = $(this).data('href'); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fiddle: http://jsfiddle.net/nikoloza/RY6Fd/