简体   繁体   中英

I would like a way to get individual anchor vars from a url and then apend all links within a specific <div> with the anchor vars

I would like a way to get individual anchor vars from a url and then apend all links within a specific with the anchor vars.

ie Current url for get vars: http://www.bestforbusiness.com#a_aid=affname&a_bid=34837e17

current links in div for replacement: <a href="http://australia.bestforbusiness.com">Australia</a>

The result whould be: <a href="http://australia.bestforbusiness.com#a_aid=affname&a_bid=34837e17">Australia</a>

I dont mind if it is done with javascript or Jquery just need some help stiching it all together as i am a noob when it comes to javascript.

Hope this is clear enough, thanks in advance

Try this:

$(document).ready(function(){
    var anchor_vars = document.location.hash;
    $("#target_div a").each(function(idx, item) { // REPLACE target_div with proper id
        $(item).attr('href', $(item).attr('href') + anchor_vars);
    });
});

Using Jquery

var customAnchorVars="#a_aid=affname&a_bid=34837e17";
$("div a").each(function()
{
  $(this).attr("href",$(this).attr("href")+customAnchorVars);

})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM