Home > OS >  How to use   inside of div > script
How to use   inside of div > script

Time:08-22

I want to use &nbsp inside of my script :

              <div  id="current_date">
                <script>
                  function CurrentDate() {
                    let current = new Date();
                    let cDate = current.getDate()   ' - '   (current.getMonth()   1)   ' - '   current.getFullYear();
                    let cTime = current.getHours()   ":"   current.getMinutes()   ":"   current.getSeconds();
                    let dateTime = cDate   ' '   cTime;
                    document.getElementById("current_date").innerHTML = dateTime;
                  }
                  setInterval(CurrentDate, 1000);
                </script>
            </div>

I don't know where to do it inside of this div I'm used to do it like this :

                <span style="font-weight: bold">&nbsp;Flash&nbsp;News</span>

Any Idea ?

CodePudding user response:

You can use the html code in your string as it goes to innerHTML anyway. So for example let dateTime = cDate '&nbsp;' cTime; works

CodePudding user response:

I solved my issue using a css : white-space: nowrap;:

My code :

              <div  id="current_date" style="white-space: nowrap;">
                <script>
                  function CurrentDate() {
                    let current = new Date();
                    let cDate = current.getDate()   ' - '   (current.getMonth()   1)   ' - '   current.getFullYear();
                    let cTime = current.getHours()   ":"   current.getMinutes()   ":"   current.getSeconds();
                    let dateTime = cDate   '<br>'   cTime;
                    document.getElementById("current_date").innerHTML = dateTime;
                  }
                  setInterval(CurrentDate, 1000);
                </script>
            </div>
  • Related