Created
March 9, 2015 16:33
-
-
Save austra/51191fe7fd043ae31ae8 to your computer and use it in GitHub Desktop.
rails jquery unobtrusive onclick
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
Obtrusive: | |
link_to 'Another link with obtrusive JavaScript', '#', | |
:onclick => 'alert("Please no!")' | |
Unobtrusive: | |
rails: | |
link_to 'Link with unobtrusive JavaScript', | |
'/actual/url/in/case/javascript/is/broken', | |
:id => 'my-link' | |
jQuery: | |
$('#my-link').click(function (event) { | |
alert('Hooray!'); | |
event.preventDefault(); // Prevent link from following its href | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment