Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A simple shim for the HTML5 formaction attribute.
# Test for formaction attribute support in Modernizer.
Modernizr.addTest 'formaction', 'formaction' of document.createElement('input')
# Shim for formaction attributes on buttons and inputs.
$.fn.shimFormAction = ->
return this if Modernizr.formaction
this.each ->
$(this).find 'input,button'
.filter '[formaction!=""][formaction]'
.on 'click', ->
$this = $ this
$this.closest('form').attr 'action', $this.attr('formaction')
Modernizr.addTest('formaction', 'formaction' in document.createElement('input'));
$.fn.shimFormAction = function() {
if (Modernizr.formaction) {
return this;
return this.each(function() {
return $(this).find('input,button').filter('[formaction!=""][formaction]').on('click', function() {
var $this = $(this);
$this.closest('form').attr('action', $this.attr('formaction'));
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment