Search code examples
htmlcsswhitespace

How to use   inside of div > script


I want to use &nbsp inside of my script :

              <div class="badge-danger" 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 ?


Solution

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

    My code :

                  <div class="badge-danger" 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>