Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-06-2012, 05:35 AM   PM User | #1
FutureWebDev
New Coder

 
Join Date: May 2012
Posts: 30
Thanks: 9
Thanked 0 Times in 0 Posts
FutureWebDev is an unknown quantity at this point
Thumbs up querySelectorAll() NodeList Usage

Code:
function themeOne() {

	var thm = document.querySelectorAll("div.articles");
	for( i = 0; i < thm.lenght; i++)
	document.thm[i].style.border = "5px solid red";

}
So all I'm trying to do here is to change the styles of the div's that have a class attribute with the value "articles". The function call works and a NodeList is created and placed in the variable thm. But before the first pass of the for loop, firebug is telling me that thm is undefined.

You can see in the picture below that thm was infact defined and the NodeList was properly created and placed in the variable.

Can someone tell me why thm is being returned undefined?


querySlectorProblem by FutureWebDev, on Flickr

Last edited by FutureWebDev; 05-06-2012 at 06:49 AM..
FutureWebDev is offline   Reply With Quote
Old 05-06-2012, 06:33 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,462
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
You haven't defined thm.lenght - possibly you meant to type thm.length
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
FutureWebDev (05-06-2012)
Old 05-06-2012, 06:37 AM   PM User | #3
FutureWebDev
New Coder

 
Join Date: May 2012
Posts: 30
Thanks: 9
Thanked 0 Times in 0 Posts
FutureWebDev is an unknown quantity at this point
Quote:
Originally Posted by felgall View Post
You haven't defined thm.lenght - possibly you meant to type thm.length
LOL. Well at least I got some good practice at posting. Thanks for being my ritalin replacement.
FutureWebDev is offline   Reply With Quote
Old 05-06-2012, 06:45 AM   PM User | #4
FutureWebDev
New Coder

 
Join Date: May 2012
Posts: 30
Thanks: 9
Thanked 0 Times in 0 Posts
FutureWebDev is an unknown quantity at this point
This Doesn't Work
Code:
function themeOne() {

	var thm = document.querySelectorAll("div.articles");
	for( i = 0; i < thm.lenght; i++)
	document.thm[i].style.border = "5px solid red";

}
This Does Work
Code:
function themeOne() {

	var thm = document.querySelectorAll("div.articles");
	for( i = 0; i < thm.length; i++)
	document.thm[i].style.border = "5px solid red";

}
Thanks Felgall
FutureWebDev is offline   Reply With Quote
Reply

Bookmarks

Tags
futurewebdev, javascript, queryselectorall

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:21 AM.


Advertisement
Log in to turn off these ads.