Welcome Guest [Log In] [Register]
We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Script returns null or not object error
Topic Started: Jul 17 2008, 02:11 PM (331 Views)
Crystatic
Member
 *   *  
Quote:
 


<script type="text/javascript">
<!--

g=document.getElementsByTagName("p")

for ( j=0; j<=g.length; j++) {

if ( g[j].className == "text1" ) {

g[j].className="text2";




} }

-->
</script>


Simple script that sets all the <p> tags with a class already set to "text1" to now have a class of "text2". But it returns an error:

Quote:
 
g[...].className is null or not an object



Does anyone know the cause of this?
Offline Profile Quote Post Goto Top
 
Codes Rock
Member Avatar
Member
 *   *   *   *  
Quote:
 
<script type="text/javascript">
<!--

g=document.getElementsByTagName("p")

for ( j=0; j<=g.length; j++) {

if ( g[j].className == "text1" ) {

g[j].className="text2";




} }

-->
</script>


Code:
 

<script type="text/javascript">
x=document.getElementsByTagName("p");

if ( x[0].className == "text1" ) {

x[0].className="text2";

}

-->
</script>


The above code will work perfectly as tested on Firefox and IE. Hope this helps!
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · zIFBoards - Skinning & Code Support · Next Topic »
Add Reply