Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carmelyne/7314 to your computer and use it in GitHub Desktop.
Save carmelyne/7314 to your computer and use it in GitHub Desktop.
// Examples:
//
// HTML:
// <form action='messages/1/mark_unread'><input type='submit' class='button_to_link' value='Mark Unread'/></form>
//
// Rails:
// button_to "Mark as unread", mark_as_unread_message_path(message), :method => :put, :class => "button_to_link"
//
// jQuery:
// $(document).ready(function() {
// $('.button_to_link').button_to_link()
// });
//
jQuery.fn.button_to_link = function() {
// return the jQuery object for chaining
return this.each(function(button){
var form = button.parents('form');
form.after('<a href="' + form.attr('action') + '" class="button_link_to">' + button.attr('value') + '</a>');
form.hide();
form.next('a.button_link_to').click(function(){
form.submit();
return false;
});
})
});
// Or you could just use a button and style it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment