Form to Link 1.0
Created Thursday 1st of January 1970 by Andreas Lagerkvist
Copyright © 2010 Andreas Lagerkvist (andreaslagerkvist.com)
What it Does
Run this plug-in on a form or an input[type=submit] and it will insert a link after the element you run it on which, on click, will submit said form.
How to Use
jQuery('#post-comment input[type=submit]').formToLink();
Example
Example Code
HTML
<div id="jquery-form-to-link-example">
<form method="post" action="">
<p>
<input type="submit" value="Delete comment"/>
</p>
</form>
</div>
JS
jQuery('#jquery-form-to-link-example form').formToLink();
Source Code
jQuery.fn.formToLink = function (c) {
var cls = c || 'jquery-form-to-link';
return this.each(function () {
var t = $(this);
var form = t.is('form') ? t : t.parents('form').eq(0);
var input = t.is('input') ? t : t.find('input[type=submit]');
$('<a href="#" class="' + cls + '">' + input.val() + '</a>').insertAfter(t).click(function () {
form.submit();
return false;
});
});
};