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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:09:48+00:00 2026-06-06T00:09:48+00:00

Using Jquery , I have an array result [<a href=><img src=image1></a>,<a href=><img src=image2></a>] if

  • 0

Using Jquery ,

I have an array result

[<a href=""><img src="image1"></a>,<a href=""><img src="image2"></a>]

if I try to do each I only get the first one in array ,

how could I split this so I could do

$.each(my_array, function (index, value) {
     this.parent().attr.('href',this.src);// assign image as href to parent
});

here is bad try

http://jsfiddle.net/ZZVXf/6/

Please note that array above is returned to my by imagesLoaded plugin for jquery and I canot select parent directly since it is not within the result , ZI must go by element.parent()
any help is appreciated. thnx!

  • 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-06T00:09:49+00:00Added an answer on June 6, 2026 at 12:09 am

    Given the following HTML:

    <a href=""><img src="image1"></a><a href=""><img src="image2"></a>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

    And a jQuery selector which catches only these elements, in this case simply:

    var my_array = $('a');
    

    You would do:

    $.each(my_array, function(i, el) {
        el.href = $(el).children('img').attr('src');
    });
    

    Example


    If your selector is on the img tags:

    var my_array = $('img');
    

    You would do:

    $.each(my_array, function(i, el) {
        $(el).parent().attr('href', el.src);
    });
    

    Example

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

Sidebar

Related Questions

I have a JQuery (using JQuery 1.4.2) problem that exhibits only in IE8 in
I am using jQuery and PHP. I have a JavaScript array , when I
I am using jQuery 1.7.1 (but that's probably irrelevant). I have several JavaScript arrays
I have created tabs by using jQuery API and have bound one event handler
Using jQuery UI's Droppable I have made a shelf type thing where the items
i have some code using jquery mobile + phonegap and run it on my
I have some tabs using jQuery UI which work just fine, but I want
I have problem while using jquery maskedinput with asp.net textbox. I have a check
I have been using Jquery alot lately an was wondering if I should use
I have just started using jQuery and although following code gets the job done,

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.