user2897282 user2897282 - 2 months ago 9
HTML Question

How to pass variable in anchor tag

I am using this anchor tag to make a call in android using cordova.

<a class="lft" href="tel:7767051447">Call</a>


Instead of number i want to give variable value.

I have number in

var phone_no


How do i pass variable instead of static number?

Answer

You could give the anchor an id:

<a class="lft" href="tel:7767051447" id="phone">Call</a>

and then update the href attribute:

var phone_no = '12345';
document.getElementById('phone').href = 'tel:' + phone_no;