Carlos Carlsen
Carlos Carlsen

Reputation: 373

How do I show a JS variable on the TITLE tag?

<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <p id="timer"></p>
  <script>
  var a = 30;
  var b = 1;

  var c = document.getElementById('timer').innerHTML = a - b;
 </script>
</body>
</html>

Thanks for taking your time to look at this!

How would I show VARIABLE C inside the HTML TITLE tag??

so:

<title>SHOW WHAT VARIABLE c IS EQUAL TO</title>

The point for this is to make a countdown timer that will show your time in your tab so you don't have to keep checking. Also, right now it just subtracts 1, how would I make it KEEP subtracting??

THANK YOU!!

I appreciate it

Upvotes: 3

Views: 6057

Answers (2)

DeepakJ
DeepakJ

Reputation: 388

You can use following code in javascript

  var a = 30;
  var b = 1; 
  var c = document.getElementById('timer').innerHTML = a - b;
  window.document.title = c;

Upvotes: 1

Oleksandr T.
Oleksandr T.

Reputation: 77482

You can use document.title, like so

  var a = 30;
  var b = 1;

  var c = document.getElementById('timer').innerHTML = a - b;
  document.title = c;

Upvotes: 9

Related Questions