Reputation: 3501
I'm trying to pull the URL from the link and assign it to the window.location and it's not working. I know I'm close, what am I doing wrong?
JavaScript:
$(document).ready(function () {
$("#mypage").attr("href", $("#redirectme").attr("href") );
window.location + "#redirectme";
});
HTML:
<a href="http://www.google.com" id="mypage">My link</a>
Upvotes: 0
Views: 1497
Reputation: 141839
You need to use assignment (=
) instead of addition (+
):
window.location = $("#mypage").prop("href");
Demo (Waits 5 seconds, so you can see it, and then redirects)
Upvotes: 2
Reputation: 19241
$(document).ready(function () {
window.location = ("#mypage").attr("href") + "#redirectme";
});
<a href="http://www.google.com" id="mypage">My link</a>
Upvotes: 0