S
S
seraphi2020-08-04 11:03:02
JavaScript
seraphi, 2020-08-04 11:03:02

How to make changing numbers and make them both work?

There is not enough space in the header to insert 2 numbers, so I would like to make it so that the number is displayed, but only mobile operators change (the numbers are identical, only the operators differ), how can this be implemented, and so that both numbers would work correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Khegay, 2020-08-04
@seraphi

<a id="phone" href=""><a/>

document.addEventListener('DOMContentLoaded', function() {
  var link = document.getElementById('phone');
  var a = '+7(123) 123-45-67';
  var b = '+8(321) 123-45-67';
  
  link.innerText = b;
  link.setAttribute('href', 'tel:' + b);
  
  setInterval(function() {
    link.innerText = link.innerText === b ? a : b;
    link.setAttribute('href', 'tel:' + link.innerText);
  }, 1000);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question