Skip to main content

Append Parameter to Anchor HREF by Class

By May 30, 2020No Comments

I wanted the parameter of a URL to append itself to anchor href by class like the param being ?ref=1 from URL being appended to <a href=””>my link</a> so when the link is clicked the new URL is

	var x, i;
	x = document.querySelectorAll(".param");
	for (i = 0; i < x.length; i++) {
		x[i].href +=;

All I need to do on is assign a special class to each link I want the parameter included with.

<a href="" class="param">my link</a>

Contact us to learn more about Adopt the Web for your business

Author Jarod Thornton

More posts by Jarod Thornton