Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Adds a test for the html5 'form' attribute. #640

merged 3 commits into from

3 participants


Credit goes to Ryan Seddon for the test.


Closing this for now whilst I explore a better way of detecting it.


Tested on IE 6 - 10, Chrome, Opera, Firefox and seems to be working lovely now - I just had to slightly alter Ryan's code.



The hole try catch block looked a little bit suspicious to me. As it turns out it was only added to workaround a bug in IE6/7 (busted distinction between content attributes and idl attributes).

I think you should document this error. Without a comment other developers could think that this code is not bulletproof, but it is :-)


@aFarkas Thanks - will do


We should let this sit for a while and see if anyone else has a better solution.

From my findings both the form and input elements need to exist in the DOM to get correct results.


The error is not thrown because IE6/7 doesn't let you append the form. It is thrown, because we try to change the form attribute, which is readonly. And if the attribute is readonly, the feature can not be supported. So the catch part is a real part of the test.

I made a jsfiddle to make this more clear.



I would like move this forward. What exactly is your problem with the current solution? I changed the detection to use document.createAttribute, so that all browsers have the same code path.

You can find my new proposal here:


@aFarkas ok fair enough the createAttribute check is a good idea I'm happy to move with this one then.


Updated the test.

@aFarkas aFarkas merged commit 3102b23 into Modernizr:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 23, 2012
  1. @danielchatfield

    Added 'formattribute' test

    danielchatfield authored
    Fixes #639
  2. @danielchatfield
Commits on Jul 25, 2012
  1. @danielchatfield
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 0 deletions.
  1. +29 −0 feature-detects/forms-formattribute.js
29 feature-detects/forms-formattribute.js
@@ -0,0 +1,29 @@
+// Detects whether input form="form_id" is available on the platform
+// E.g. IE 10 (and below), don't support this
+Modernizr.addTest("formattribute", function() {
+ var form = document.createElement("form"),
+ input = document.createElement("input"),
+ div = document.createElement("div"),
+ id = "formtest"+(new Date().getTime()),
+ attr,
+ bool = false;
+ = id;
+ //IE6/7 confuses the form idl attribute and the form content attribute
+ if(document.createAttribute){
+ attr = document.createAttribute("form");
+ attr.nodeValue = id;
+ input.setAttributeNode(attr);
+ div.appendChild(form);
+ div.appendChild(input);
+ document.documentElement.appendChild(div);
+ bool = form.elements.length === 1 && input.form == form;
+ div.parentNode.removeChild(div);
+ }
+ return bool;
Something went wrong with that request. Please try again.