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

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 01-23-2012, 12:11 PM   PM User | #1
misfortune
New to the CF scene

 
Join Date: Jan 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
misfortune is an unknown quantity at this point
Question Array of images

I'm trying to get a specific set of images into an array but it's not working.

Code:
y = document.getElementsByTagName('img');
The above works but isn't specific enough.

Code:
y = document.getElementById('test').getElementsByTagName('img');
The above is what I want but doesn't work. How can I achieve this?

Basically I need to use...
Code:
$(y[z]).css("display", "none");
on some images in a loop based on specific conditions but only the ones inside the specific div.
misfortune is offline   Reply With Quote
Old 01-23-2012, 02:51 PM   PM User | #2
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,763
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
As a test, what does the following display in your program?
Code:
y = document.getElementById('test').getElementsByTagName('img');
for (var i=0; i<y.length; i++) { alert(y[i].src); }
If shows nothing, then post more of your code.
jmrker is offline   Reply With Quote
Old 01-23-2012, 03:41 PM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,584
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
It looks like you’re using jQuery in the last example which is why I moved the thread here. Now, jQuery makes it really easy to select certain elements but we need to know more about the markup (HTML) to be able to give you an appropriate solution.

To translate the “The above is what I want but doesn't work.” code into jQuery:
Code:
y = $('#test img');
You can then do
Code:
y.css('display','none');
but you could even do
Code:
$('#test img').css('display','none');
right away.
The first method with declaring a variable might save some resources, though.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Reply

Bookmarks

Tags
array, document, element, image, javascript

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 06:06 AM.


Advertisement
Log in to turn off these ads.