-5

I have been working on an html page for some time now and now I want to display the ever changing value of a JavaScript variable after some text in the title. ex:
___/TEXT :: TEXT: var \ _________
If this is possible in JS and html how would I do it. If I have to I am open to a little PHP, but nothing to complicated.

zcool 99
  • 27
  • 1
  • 8

2 Answers2

2

Look over Javascript Basics

Web-crawlers update their indices if your title changes, as a heads-up note.


let variable = "-hello world-";

document.title  = "___/TEXT :: TEXT: " + variable + " \ _________";
console.log(document.title);
/*
OR
document.title  = "___/TEXT :: TEXT: var \ _________";
document.title  = document.title.replace('var', variable);
*/
Alex
  • 2,164
  • 1
  • 9
  • 27
  • This just looks like changing the text inside of a document. I want to display the variable in the element. – zcool 99 Jul 03 '18 at 15:14
  • what does the `let` mean? p.s. I can code in JavaScript but there are still lost of things i don't know about >~ – zcool 99 Jul 03 '18 at 15:18
  • Refer to [`What's the difference between using “let” and “var” to declare a variable in JavaScript?`](https://stackoverflow.com/questions/762011/whats-the-difference-between-using-let-and-var-to-declare-a-variable-in-jav). `let` keyword is a strict scoped variable definition. – Alex Jul 03 '18 at 15:19
  • 1
    Thanks never knew that. Then if I understood it right then I could use my already defined `var` instead of your `let` variable? – zcool 99 Jul 03 '18 at 15:21
  • No problem. :) Make sure to select the best answer to not keep this question hanging. – Alex Jul 03 '18 at 15:22
0

Please check this: https://developer.mozilla.org/en-US/docs/Web/API/Document/title

let title = 'my new title';
document.title = title;
schildi
  • 136
  • 7