Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Array of images

  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,071
    Thanks
    38
    Thanked 498 Times in 492 Posts
    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.

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,623
    Thanks
    6
    Thanked 1,001 Times in 974 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •