Created
December 30, 2010 23:09
-
-
Save hisea/760464 to your computer and use it in GitHub Desktop.
togglable comment box
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
<a href="javascript:void(0)" class="toggleLink" data-mid="<%= message.id %>">Link to my partial</a> | |
<div id="add_comment<%=message.id%>" style="display:none"> | |
Comment box | |
</div> |
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(){ | |
// notice the hash(#) and dot(.) before the elements? A hash represents an HTML ID and a | |
// dot represents an HTML class. I made the link have a class, and the toggle_div an ID | |
// but you may use whatever you'd like, just make sure if you're referencing an ID that you put | |
// a hash(#) before it and if you're referencing a class, make sure you put a dot(.) before it. | |
// this javascript should also be in your application.js, or some other JS file. The whole reason link_to_remote and | |
// those other "remote" tags were deprecated is to maintain unobtrusive javascript (take the JS out of the views). | |
// this makes for cleaner, separated, more modular code. | |
$('.toggleLink').click(function(){ | |
var mid = this.getAttribute('data-mid'); | |
$('#add_comment'+mid).toggle(); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment