Should href be set with prop() or attr()?

Francisc picture Francisc · Aug 12, 2013 · Viewed 9.9k times · Source

If I want to change the href of a link dynamically, should I do so using prop() or attr()?

Answer

SmokeyPHP picture SmokeyPHP · Aug 12, 2013

You would use .attr(), as .prop() is more commonly used for boolean properties such as checked, selected, etc - though it is certainly possible with .prop it's arguably less clear as per your intent

Though I do believe that ultimately they are very similar (or used to be) functionality-wise

Just a note: the jQuery API site seems to follow the boolean 'sway':

.prop() - Examples use checked and disabled

.attr() - Examples use alt title and src