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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:31:51+00:00 2026-06-01T01:31:51+00:00

I have something like this: <img class=photo src=www.example.com /> <img class=photo src=www.example2.com /> <img

  • 0

I have something like this:

<img class="photo" src="www.example.com" />
<img class="photo" src="www.example2.com" />
<img class="photo" src="www.example3.com" />

And I need to get this:

<a href="www.example.com" class="link">
    <img class="photo" src="www.example.com" />
</a>
<a href="www.example2.com" class="link">
    <img class="photo" src="www.example.com2" />
</a>
<a href="www.example3.com" class="link">
    <img class="photo" src="www.example.com3" />
</a>

I need to add the link, the href with the same code as the SRC of each image, and a class.

I was trying to do it like this:

$('.photo').wrapAll('<a>');

But it doesn’t even work.
What am I doing wrong?

  • 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-01T01:31:52+00:00Added an answer on June 1, 2026 at 1:31 am

    Because the hrefs will all be different, you’ll need to use each.

    $('img.photo').each( function() {
        var $img = $(this),
            href = $img.attr('src');
        $img.wrap('<a href="' + href + '" class="link"></a>');
    });
    

    Note that wrapAll isn’t what you want anyway as it will take all the elements and wrap them with a single anchor tag. If you weren’t using an anchor that needs a different href for each element, wrap would work by itself and wrap each one individually.

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

Sidebar

Related Questions

I have something like this set up: class CategoryPage (webapp.RequestHandler): def get(self): ** DO
I have a code block looking something like this: <p class=cont> <a href=otherpage.php class=link><img
I have some text with images inside it. For example like this texttext<img src=2011-08-15/4/img/123.JPG
I have something like this in my Spring Application: public class Book{ public Book(){
I have something like this currently: <div class = className style = position: absolute;
I have some jQuery code something like this: $(document).ready(function() { $(img.off).click(function() { alert('on'); $(this).attr('class',
I have a list like this: <ul> <li id=adm-thumb onclick=javascript:addBanner('bowling.jpg');> <div class=adm-tick></div> <img src=img/banners/bowling.jpg
i have some photos: <div class=photo> <a rel=example_group href=http://download.com/79.jpg><img class=edit_multimedia_img src=http://download.com/79.jpg></a> <a rel=example_group href=http://download.com/80.jpg><img
I have some code like this: <div><%# DataBinder.Eval(Container.DataItem, M_ClassProperty) %></div> <img src='<%# DataBinder.Eval(Container.DataItem, M_AnotherClassProperty).To<string>()
I have a page containing a series of tags like this <a class=IMG href=#

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.