Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript, getElementById and style not working: Uncaught TypeError: Cannot read property 'style' of null

I have this code here:

document.getElementById('success').style.display("block");
document.getElementById('success').text("aaaa"); 

and I get this error, why?

Uncaught TypeError: Cannot read property 'style' of null 

<span id="success" style="color:#FFF; display:none;"></span>

I moved my code to bottom of the page and I get this new error now

Uncaught TypeError: Property 'display' of object #<CSSStyleDeclaration> is not a function

like image 714
user1269625 Avatar asked Mar 23 '23 00:03

user1269625


1 Answers

Should be:

var elSuccess = document.getElementById('success');
elSuccess.style.display = 'block';
elSuccess.innerText = 'aaa';
like image 191
Todd Avatar answered Apr 25 '23 04:04

Todd