[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<head>
<title></title>
<style type="text/css">
.nodisplay{
display: none;
}
</style>

<script type="text/javascript">
<!--
var theElement;
theElement = document.getElementById("test");
theElement.className="nodisplay";
-->
</script>

</head>
<body>
<div id="test"> CSS Rules in Action </div>
</body>
</html>]

I want this text to disappear, but I get object theElement is undefined or null. Help I think it is simple

<div id="test"> doesn't exist when your script is being run. Usually, when you are working with the DOM, you would like to wait untill the whole DOM is loaded.

try running your code afer the window is loaded.

window.onload = function() {

// .. your code

};

or use the specific event attachment functions for different browsers.

Edit: I meant "event handler" attachment functions...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.