Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:56:00+00:00 2026-05-27T22:56:00+00:00

I have something along the lines of : html : <div class=myclass> <img class=otherclass

  • 0

I have something along the lines of :

html :

<div class="myclass">
    <img class="otherclass" src="image1.png" />
</div>

<div class="myclass">
    <img class="otherclass" src="image2.png" />
</div>

<div class="myclass">
    <img class="otherclass" src="image3.png" />
</div>

Javascript (jQuery):

alert($('.myclass img.otherclass').attr('src'));

I am able to get/alert an image src no problem (allthough I cant remember if its the first or last but that is besides the point) – What i want to to is spécicly get the first and last images (src),

I have tried :

alert($('.myclass:first img.otherclass').attr('src'));
alert($('.myclass:last img.otherclass').attr('src'));

But this does not seem to work for me. (I cannot change the HTML markup)

Am I using :first and :last correctly or should I be using something like .find() …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:56:01+00:00Added an answer on May 27, 2026 at 10:56 pm

    Seem to work fine for me: http://jsfiddle.net/RfHps/

    However you could try the following:

    var images = $('.myclass img.otherclass');
    
    alert(images.first().attr('src'));
    alert(images.last().attr('src'));
    

    Also note that its actually faster to use .first()/.last() than selectors – see http://jsperf.com/first-performance/2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i have something along the lines of private ObservableCollection<ViewModel> _internal; public ObservableCollection<ViewModel> BoundInternal{get;set};
I have a page using something along the lines of <meta http-equiv=refresh content=0;url=http://example.com/ />
I have something like this: <div class=content> <a href=#>A</a> </div> <div class=content> <a href=#>B</a>
onI have the following html structure: <div> <ul> <li class=gravity-form></li> <li class=gravity-form-divider></li> </ul> </div>
Currently, I have this line: this.html(this.html().replace(/\x3C\x2F?[^\x3E]+\x3E/gi, '')); But, I would like something along the
I have some html that looks like this: <div class=block> <div id=item1></div> <div id=item2></div>
I have something like this set up: class CategoryPage (webapp.RequestHandler): def get(self): ** DO
I'm trying to achieve something along the lines of... UserControl (MyRepeater) <p>Control Start</p> <asp:Repeater
Given the following HTML: <asp:content id=Content1 contentplaceholderid=mainContent runat=server> <div class=scrollRow> <table width=100%> <tr> <td
For a long time now I have noticed something annoying when working on Web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.