Created
January 29, 2016 14:26
-
-
Save rutger1140/4282a6449de15665d299 to your computer and use it in GitHub Desktop.
Simple javascript helper to find link element in block and follow link on click
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
function clickableBlock() { | |
// Each element with data-clickable is searched for an link and onclick | |
// the link is followed | |
$("[data-clickable]").each(function(){ | |
var $this = $(this), | |
link = $this.find("a").attr("href"); | |
if(link) { | |
$this.click(function(){ | |
window.location = link; | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: