-3
I have a javascript variable BASE_URL='http://localhost/BKTHP_WEB_NEW/';

Now I want to insert it inside a

something like <a href="BASE_URL+\view">
Vikash Jha
  • 35
  • 6

2 Answers2

3

Use setAttribute to set the variable as a value for href

var BASE_URL='http://localhost/BKTHP_WEB_NEW/';
document.querySelector('a').setAttribute('href',BASE_URL)
<a href="">Link
ellipsis
  • 12,049
  • 2
  • 17
  • 33
1

You can use setAttribute on your a tag, and set the href dynamically

<a id="replace" href="">YOUR LINK</a>
const BASE_URL='http://localhost/BKTHP_WEB_NEW/';
document.querySelector('#replace').setAttribute('href', BASE_URL);
Smokey Dawson
  • 8,827
  • 19
  • 77
  • 152