1 line
1.8 KiB
JSON
1 line
1.8 KiB
JSON
{"name":"removeAttr","type":"method","title":".removeAttr()","deprecated":null,"removed":null,"desc":"Remove an attribute from each element in the set of matched elements.","categories":["attributes","manipulation/general-attributes","version/1.0","version/1.4","version/1.7"],"entries":[{"return":"jQuery","signatures":{"added":"1.0","argument":{"desc":"An attribute to remove; as of version 1.7, it can be a space-separated list of attributes.","name":"attributeName","type":"String"}},"examples":{"desc":"Clicking the button changes the title of the input next to it. Move the mouse pointer over the text input to see the effect of adding and removing the title attribute.","code":"\n(function() {\n var inputTitle = $( \"input\" ).attr( \"title\" );\n $( \"button\" ).click(function() {\n var input = $( this ).next();\n\n if ( input.attr( \"title\" ) === inputTitle ) {\n input.removeAttr( \"title\" )\n } else {\n input.attr( \"title\", inputTitle );\n }\n\n $( \"#log\" ).html( \"input title is now \" + input.attr( \"title\" ) );\n });\n})();\n","html":"\n<button>Change title</button>\n<input type=\"text\" title=\"hello there\">\n<div id=\"log\"></div>\n"},"longdesc":"\n <p>The <code>.removeAttr()</code> method uses the JavaScript <code>removeAttribute()</code> function, but it has the advantage of being able to be called directly on a jQuery object and it accounts for different attribute naming across browsers.</p>\n <p><strong>Note:</strong> Removing an inline <code>onclick</code> event handler using <code>.removeAttr()</code> doesn't achieve the desired effect in Internet Explorer 6, 7, or 8. To avoid potential problems, use <code>.prop()</code> instead:</p>\n <pre><code>\n$element.prop( \"onclick\", null );\nconsole.log( \"onclick property: \", $element[ 0 ].onclick );\n </code></pre>\n "}]} |