html - Cannot change href attribute with jQuery -
i accessing links on webpage jquery, following code:
$('a[href]').each(function() { $(this).attr('class', 'visited'); $(this).attr('href', '#'); }) the class on link changed, href not. there preventing me changing/altering href?
edit:
i updated code following:
$('a[href]').each(function() { $(this).addclass('visited'); this.href = '#'; }) however, although works on websites, doesn't work on news.yahoo.com. reasons why so?
for href, want use .prop() instead of .attr().
for classname, in cases want use .addclass() instead of overwriting entire class attribute.
Comments
Post a Comment