Should href be set with prop() or attr()? [duplicate]

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

Leave a Comment