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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:40:13+00:00 2026-06-09T18:40:13+00:00

I have a little script that takes an image’s alt tag an adds it

  • 0

I have a little script that takes an image’s alt tag an adds it as text as such:

 $(".field-item a img").each(function(i, ele) {
          $(".field-item").append("<span>"+$(ele).attr("alt")+"</span>");
      });​

The issue I am having is I am getting duplication where every alt tag is added to every image as text. So for “image-1“, image-1 and image-2 get added as text where I only want the corresponding alt tag added as text.

I tired using .closest() e.g.

$(".field-item").closest().append("<span>"+$(ele).attr("alt")+"</span>");

… but that did not seem to do the trick. I have fiddle here:

http://jsfiddle.net/6pAZE/4/

  • 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-09T18:40:15+00:00Added an answer on June 9, 2026 at 6:40 pm

    You can use the closest() method, currently you are selecting all the elements with class of field-item in each iteration, try the following:

     $(".field-item a img").each(function(i, ele) {
         var alt = this.alt;
         $(this).closest(".field-item").append("<span>"+alt+"</span>");
         // or $(this).after("<span>"+alt+"</span>");
     });
    

    Fiddle

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

Sidebar

Related Questions

I have a little script that checks for cookies and I was wondering how
I have this little script that shows one wisdom each day. so I have
I have a little python script that I am using to download a whole
I have a form that takes a little while for the server to process.
So I have this neat little javascript function that I'm using to print text
So I have been working on writing a script that takes in input from
I have a simple search script that takes user input and searches across directories
I'm working on a little script that generates a sprite sheet. I have 6
I have a little script to run a search daemon, like: run.sh : cd
I'm a jQuery newbie, and I have trouble with a little script I created.

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.