jQuery add attribute to html element and remove

You can add attributes using attr like below:

    $('#yourid').attr('name', 'value');

To remove:

    $('#yourid').removeAttr('name');

However, for DOM properties like checked, disabled and readonly, the proper way to do this (as of JQuery 1.6) is to use prop.

    $('#yourid').prop('name', 'value');

To remove:

    $('#yourid').removeProp('name');

By Keenlio, July 25, 2014

What do you think?

Leave a Reply

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


3 + = seven

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>