Append URL to Existing Links

Glenn Blog Leave a Comment

This snippet is a quick way to add a predefined URL to the front of an existing set of links (typically relative).

$( document ).ready(function() {
$(".navbar a").each(function(){
   $old_url = $(this).attr('href');
   $new_url = 'https://slickmedia.co.uk/'+$old_url;
   $(this).attr('href',$new_url);
});
});

Simply replace the original target link(s) and the URL.

Potential uses are where you have relative links (perhaps anchors) on a home page and then want to refer links on other pages back to the home page using the same menu system.

About the Author
append url to existing links Append URL to Existing Links 0da77002febbfe28d15144a57bbcc2c9 s 180 d mm r g

Glenn

A highly experienced Web Designer / Web Developer (Webflow, WordPress, Weebly & Custom), Front-end / Back-end Developer & New Media Specialist, with extensive knowledge of a wide spectrum of technologies in the Development and Creative Industries, built up over a number of years.