Pregunta

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

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top