I have three links that unfortunately do not have a class or an id. Their href is static. I want to attach the same parameter to all three of them at the end of the URL, so my idea is to identify them based on their href value but I do not know how to do this.
The links look like:
<ul class="links primary-tabs">
<li><a href="/user">Login</a></li>
<li><a href="/user/register">Register</a></li>
<li><a href="/user/password">Forgot Password</a></li>
</ul>
So far I have the following code where $destination is a PHP variable:
$(document).ready(function(){
$(".page-user .primary-tabs a").attr("href", "/user/register?destination='.$destination.'");
});
This would, of course, change all of the three links to /user/register?destination=….
Can anyone help me out on how to attach $destination to all of the three links preserving their original href?
Thanks
You can use
.attr()with a function, like this:This just appends that querystring to each,
hrefbeing the previous value inside the loop.