Placing Javascript in Div [closed]

0

I have this code to show this date

<script language="javascript" type="text/javascript">// <![CDATA[
now = new Date
document.write ("Esquenta Black Friday Somente Hoje  " + now.getDate() + " do " + now.getMonth() + 1, )
// ]]></script>

I needed it inside a div to use these CSS settings

.promocoes-kit {

background: #fff1dc;

 width: 80%;

 height: 50%;

  margin: auto;

 border-radius: 10px;

border: solid 4px white;

box-shadow: 3px 3px #bdbcbc5e;
}

.promocoes-kit{

 font-size: initial;

text-align: center;

 font-weight: 600;

 color: #ea9b2a;

  width: fit-content;

 padding: 10px 30px;
}

.promocoes-label{

 padding: 0;

  margin: 0;

 text-align: center;

 font-size: large;

 color: #ea9b2a;

 font-weight: 600;
}

Does anyone know how to do this? I'll use it on a LADING PAGE as a banner in Magento

    
asked by anonymous 08.11.2018 / 14:38

1 answer

2

So I realized you do not have much knowledge with Javascript , so here are some considerations:

  

1 - You are using document.write which is poorly indicated because it overwrites all your HTML      

2 - It is always best to declare variables with the keyword var or let , N > reasons.

     

3 - When you do this now.getMonth() + 1 , you will have the previous month plus a 101 being the right one to put inside parentheses to form an expression thus (now.getMonth() + 1) .

var div = document.getElementById('teste');
var datas = new Date();

div.innerHTML = 'Esquenta Black Friday Somente Hoje  ' + datas.getDate() + ' do ' + (datas.getMonth() +1);
body {
  background-color: #CCC;
}

#teste {
  background-color: green;
  color: white;
}
<div id="teste"></div>
    
08.11.2018 / 15:15