tags:

views:

51

answers:

4

Code is as follows:

<div id="compare_view" align="center">

    <div id="compv-navbar">
        <img src="image1.png"> | <img src="image2.png"> | <img src="image3.png"> | Text can be here
    </div>    
</div>

I would like to be able to manipulate all of the images within the 'compv-navbar' div.

I know I could give each image a unique ID and select them that way, but I want to manipulate all the images within that compv-navbar div at the same time.

Edit: Sorry, I would like to select it with CSS. I thought it was obvious from the tags.

+1  A: 
#compv-navbar img { 'your schnizzzle' }
ToonMariner
+1  A: 

Take a look at the JQuery "each" method: http://api.jquery.com/jQuery.each/

RWGodfrey
+4  A: 
#compare_view #compv-navbar img { } 

The first id isn't really necessary but makes it more specific and linear-like. You can go ahead and just use #compv-navbar img if you want.

If you want to manipulate with javascript, getElementById on #compv-navbar and getElementsByTagName('img') using that as a context.

jQuery-wise it would be $('#compv-navbar img')

meder
+1 for clean answer. Might be worth adding the direct descendant notation to your answer so it is even more complete:#compare_view>#compv-navbar>img{}
Gabriel
It wouldn't work in IE6 and I still have to code for that so I'll leave it as is :)
meder
A: 
/*
query for id compv-navbar and populate NodeList collection with all <img> children
NOTE: since ids _required_ to be unique within the document, asking for compare_view first is redundant
*/
var nodeList = document.getElementById( 'compv-navbar' ).getElementsByTagName( 'IMG' );
for ( var i = 0; i < nodeList.length; i++ )
  nodeList[ i ].title = 'Here is my image!'

huh, no longer has JS flavour?

#compare_view>#compv-navbar>img { content: "here WAS my image" }

Again, selector is over-specific