writeAttribute() example

The documentation on http://prototypejs.org/api/element/writeAttribute is a wee bit scarce. So here’s a quick one on usage.

To add an attribute:

$('foo').writeAttribute('title', 'bar');

To remove an attribute:

$('foo').writeAttribute('title', null);

To enable all disabled form elements (in a form with the id ‘container’):

$('container').select('[disabled="disabled"]').each(function(e) {
  $(e).writeAttribute('disabled', null);

2 thoughts on “writeAttribute() example”

  1. Thank you so much! For the life of me, I cannot understand why the documentation at the official Prototype website is so poor. Their explanation about practically everything (not just writeAttribute) seems so short and cryptic. It’s almost like they’re trying their best to hide what Prototype can do. Weird!

    It’s such a pity because from my limited experience coding with Prototype so far, it seems like a great framework.

    1. I’m glad that this has been of use.

      It annoyed me 3 years ago.
      Since then, I’ve found jQuery to be a much more usable framework.

      Happy coding 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.