tags:

views:

37

answers:

3

Say my code is as follows:

<ul>
   <li><img /></li>
   <li>
      <ul>
         <li><img /></li>
      </ul>
   </li>
</ul>

I'm trying to set a default size for the first img tag, but not affect the second one. everything I do affects the other one as well. Currently I have tried:

$('ul#gallery > li').find('img').css('width','650px');
$('ul#gallery > li img').css('width','650px');

among others, but nothing works.

A: 

Have you tried using the jQuery :first selector?

$("li img:first").css('width','650px');
gurun8
There will be about 40 images that will need to be sized, not just the first one.
steve
You may have wanted to include that in your question. What's the full list of requirements for the question?
gurun8
Yeah that was my fault, sorry... I'll be more specific next time. It was answered above, thanks
steve
A: 

I don't see a id="gallery" in your example, but assuming the following code (only the outer <ul> has the gallery id):

<ul id="gallery">
   <li><img /></li>
   <li>
      <ul>
         <li><img /></li>
      </ul>
   </li>
</ul>

then the appropriate CSS selector is ul#gallery > li > img.

Ken Bloom
Yeah there's #gallery in my actual code, just not in the example.
steve
A: 
$('ul#gallery > li > img').css('width','650px');
TiuTalk
I tried this, it doesn't affect the image at all.
steve
Ah, I fixed it. The image was inside of an `a` tag which was throwing off jQuery. Thanks.
steve