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 8256229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:47:33+00:00 2026-06-08T01:47:33+00:00

So like i wrote in the title, i have multiple elements with same class

  • 0

So like i wrote in the title, i have multiple elements with same class i fetch that class and try to check for the child image’s width/height/src of that image.

i only manage to get the height // width of the first image however i get the src of all images.

here is the html:

<a class="test">
<img src="http://www.kitchenspro.com/files/Testimonials/Large/1502046700250312a71707.jpg">
</a>
<a class="test">
<img src="http://www.kitchenspro.com/files/Testimonials/Large/40183.9461166782.jpg">
</a>
<a class="test">
<img src="http://sphotos-a.xx.fbcdn.net/hphotos-ash4/s480x480/391362_365319466870994_1543740404_n.jpg">
</a>

here is the jquery

var imagesrc= "";
var imageheight = "";
var imagewidth = "";
var i=0;
$(".test > img").each(function() {
i++;
imagesrc = $(this).attr("src");
imageheight = $(this).width();
imagewidth = $(this).height();
document.write("<br>This is image's src: " + imagesrc + " This is img height: " + imageheight + " this is width: " + imagewidth + "<br>");            
});

I apologize if i didnt present the code the right way.

Any help would be highly appreciated.

Thanks in advanced.

  • 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-06-08T01:47:35+00:00Added an answer on June 8, 2026 at 1:47 am

    Exactly what @Musa said.

    To help clean up your code and give a lesson on efficiency and native javascript, I have supplied a snippet.

    // Document Fragments are lightweight DOM containers. Append elements to this in loops and then attach the fragment to the actual DOM afterwards to increase efficiency. 
    var frag = document.createDocumentFragment();
    
    // i, or index, comes out of box in most loops.
    $(".test img").each(function(i, el) {
     // Local variables specific to each image
     var imagesrc = $(this).attr("src");
     var imageheight = $(this).width();
     var imagewidth = $(this).height();
     var message = "This is image's src: " + imagesrc + " This is img height: " + imageheight + " this is width: " + imagewidth;
    
     // Appending the node to the frag with native js
     var p = document.createElement("p");
     p.innerText = message;
     frag.appendChild(p);
    
     // Viewing the console message for fun
     console.log(message);     
    });
    
    document.body.appendChild(frag);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Like in title? have no idea how to do it I wrote something like
I have a series of commands that check whether a url looks something like
Database is like: table book: book_id, title table wrote: book_id, author_id, author_order table author:
I updated my code like Andro wrote about to me: public class ZiiziiActivity extends
I wrote a program called Hello.py that looks like this: import pygame, sys from
I wrote a method that extracts fields from an object like this: private static
Basically, what the title says. I have several properties that combine together to really
I would like to have a mapped class named Message. This class should include
Let's say that I have a bunch of records in MySQL, something like this:
I have a body map with multiple trigger points on it. I'd like a

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.