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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:27:12+00:00 2026-05-19T14:27:12+00:00

I am trying to pass along both the src and the rel tag values.

  • 0

I am trying to pass along both the src and the rel tag values. Here’s the sample input.

<img class="image" src="example.jpg" title="" rel="value" />

The following is some code that is parsing all <img> tags on a page.

add: function(src, rel) {
    if (this.cache[src]) {
        return this.cache[src];
    }
        if (this.cache[rel]) {
            return this.cache[rel];
        }
    var image = new Image();
    image.src = src;
        image.rel = rel;
    this.setStyle(image, {display: 'block'});
    if (image.complete && image.width) {
        return image;
    }
    image.onload = (function(scope) {
        return function() {
            scope.cache[src] = image;
        };
    })(this);
        jQuery(image).attr('rel', function() { image.rel } );
    return image;
},

However, this is my output.

<img src="example.jpg" style="display: block;" />

It’s as if it’s completely ignoring the rel tag. I need to pass the rel tag value from the old <img> to the new <img>.

  • 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-19T14:27:12+00:00Added an answer on May 19, 2026 at 2:27 pm

    The code is setting the properties. Not sure, but if the rel property doesn’t map to the attribute, it won’t show up.

    Also jQuery muddles the distinction between attributes and properties a bit, so I’m not sure how it treats rel.

    When you’re setting the rel, add a setAttribute() call.

    var image = new Image();
    image.src = src;
    image.rel = rel;
    image.setAttribute('rel',rel);
    

    Your original code does cause the rel property to be set, but not the attribute. This will actually set the attribute.

    You should be able to get rid of this line:

    jQuery(image).attr('rel', function() { return image.rel } );
    

    EDIT:

    Here’s an alternate solution:

    It seems that if you first set image.rel = rel;, the jQuery has no effect. Get rid of that line, and the jQuery code will work.

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

Sidebar

Related Questions

I am trying to pass a member function within a class to a function
I'm trying to pass an instance of a class between two separate classes, like
I'm trying to pass in a Base64 string into a C#.Net web application via
I'm currently trying to pass a mono threaded program to multithread. This software do
I'm trying to pass one method to another in elisp, and then have that
I am trying to pass some Subsonic collections to a client via a web
I'm trying to pass a complex object (that can be serialized, if that helps)
I'm trying to pass a null value for the first parameter in the code
I am trying to pass a dataString to to an ajax call using JQuery.
I am trying to pass an XML list to a view but I am

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.