2

My DOM looks like:

<div id="blah-1">
  <div class="class1">
     <div class="class11>
        <a href=""><img src=""></a> <b>blah</b>
        <a href=""><img src=""></a>
     </div>
  </div>
</div>

I have to change the source of the 1st or sometimes 2nd img.

I am using jQuery and don't have a strong handle with selectors just yet!

1 Answer 1

5

You can use :eq(n) to select an element at a given position:

$("#blah-1 .class1 .class11 img:eq(0)").attr("src", newSource);
$("#blah-1 .class1 .class11 img:eq(1)").attr("src", newSource);

Oh, and you're missing a closing " after class11, not sure if that's pasted code or not.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.