DOM Enlightenment Book
HTML
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
<a href='#' title="title" data-foo="dathiuhihiuhaFoo" style="margin:0;" class="yes" foo="boo" hidden="hidden">#link</a>
<h4 style="border-top:1px solid #ADADAD;padding-top:20px;margin-top:20px;"><strong>← Code Example from <a href="http://www.domenlightenment.com/" target="_blank">DOM Enlightenment Book</a> by <a href="http://www.codylindley.com" target="_blank">Cody Lindley</a></strong></h4>
<p>JavaScript code is executed on page load. Click the "Run" button in the top bar to re-run the JavaScript code. All <code>console.log()'s</code> are logged to the <a href="http://getfirebug.com/firebuglite" target="_blank">Firebug Lite</a> console below ↓.</p>
JavaScript
var atts = document.querySelector('a');
//remove attributes
atts.removeAttribute('href');
atts.removeAttribute('title');
atts.removeAttribute('style');
atts.removeAttribute('data-foo');
atts.removeAttribute('class');
atts.removeAttribute('foo'); //custom attribute
atts.removeAttribute('hidden'); //boolean attribute
//set (really re-set) attributes
atts.setAttribute('href','#');
atts.setAttribute('title','title');
atts.setAttribute('style','margin:0;');
atts.setAttribute('data-foo','dataugyuyguygygyFoo');
atts.setAttribute('class','yes');
atts.setAttribute('foo','boo');
atts.setAttribute('hidden','hidden'); //boolean attribute requires sending the attribute as the value too
//get attributes
console.log(atts.getAttribute('href'));
console.log(atts.getAttribute('title'));
console.log(atts.getAttribute('style'));
console.log(atts.getAttribute('data-foo'));
console.log(atts.getAttribute('class'));
console.log(atts.getAttribute('foo'));
console.log(atts.hasAttribute('hidden'));