(function(){
var data = new Date();
var dia = document.querySelector('.table tbody tr > td');
dia.textContent = data.getDate();
})();
I have this function in Javascript. It always returns NULL. Why does this occur?
(function(){
var data = new Date();
var dia = document.querySelector('.table tbody tr > td');
dia.textContent = data.getDate();
})();
I have this function in Javascript. It always returns NULL. Why does this occur?
I've simulated your code here and it's working fine. See if the selector is not wrong.
(function(){
var data = new Date();
var dia = document.querySelector('.table tbody tr > td');
dia.textContent = data.getDate();
})();
<table class="table">
<tbody>
<tr>
<td>data vem aqui</td>
</tr>
</tbody>
</table>
I updated your function to return the Date within an element with ID, but you can use the querySelector if it is the case:
$(function() {
var data = new Date();
var dia = document.querySelector('#aqui');
var mes = data.getMonth()+1; // Janeiro é 0!
if(mes < 10) mes = '0'+mes;
var ano = data.getFullYear();
dia.innerHTML = data.getDate() + '/' + mes + '/' + ano;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><body><pid="aqui"></p>
</body>