Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is a little snippet that allows you to change the <code>type</code> of elements in documents.</p> <p><code>jquery.type.js</code> (<a href="https://gist.github.com/1192149" rel="nofollow">GitHub Gist</a>):</p> <pre class="lang-js prettyprint-override"><code>var rtype = /^(?:button|input)$/i; jQuery.attrHooks.type.set = function(elem, value) { // We can't allow the type property to be changed (since it causes problems in IE) if (rtype.test(elem.nodeName) &amp;&amp; elem.parentNode) { // jQuery.error( "type property can't be changed" ); // JB: Or ... can it!? var $el = $(elem); var insertionFn = 'after'; var $insertionPoint = $el.prev(); if (!$insertionPoint.length) { insertionFn = 'prepend'; $insertionPoint = $el.parent(); } $el.detach().attr('type', value); $insertionPoint[insertionFn]($el); return value; } else if (!jQuery.support.radioValue &amp;&amp; value === "radio" &amp;&amp; jQuery.nodeName(elem, "input")) { // Setting the type on a radio button after the value resets the value in IE6-9 // Reset value to it's default in case type is set after value // This is for element creation var val = elem.value; elem.setAttribute("type", value); if (val) { elem.value = val; } return value; } } </code></pre> <p>It gets around the issue by removing the <code>input</code> from the document, changing the <code>type</code> and then putting it back where it was originally.</p> <p>Note that this snippet was only tested for WebKit browsers – no guarantees on anything else!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload