I have a very simple jQuery method chain that is throwing an error. All it’s supposed to do is replace the “#” with a new value (“test.html”). I’m doing this because I’m retrieving a value from a database and want to update specific links in the markup. I have verified that the href attribute is, in fact “#”. But I’m getting an “Object doesn’t support this property or method” error. I’m using jquery-1.7.1.min.js.
Can someone tell me what’s wrong with this statement:
$('a#protoPath').attr('href').html('test.html');
.attr('href')returns the current attribute contents, not another jQuery object, so it can’t be chained.You need to use
.attr('href', newValue)if you want to actually change it.If you only want to change the one link that has
"#"as itshrefyou need to change your selector, too: