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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:21:08+00:00 2026-05-11T06:21:08+00:00

Heads up: I am quite new to Javascript and have so far only written

  • 0

Heads up: I am quite new to Javascript and have so far only written very basic scripts based on jQuery. I am a quick study though..

What I am after is a way to:

1) identify tags

2) read the img tags

3) wrap the tag with an <a href> tag with a dynamic link based on the src of the img.

Example:

<img src='../../img_T/Culture/C_01/c_01_abb_005.jpg' width='310' height='180' alt='image1'> 

should become

<a href='../../img_L/Culture/C_01/c_01_abb_005.jpg'><img src='../../img_T/Culture/C_01/c_01_abb_005.jpg' width='310' height='180' alt='C 01 Abb 005'></a> 

I am thinking that reading the src of each image and writing it to a variable, then reading that variable and replacing the /img_T/ with /img_L/ and then writing that to a new variable which can then be simply added to each href.

This is how far I have gotten, but this does not work at all:

/* in the comments 'xxx' represents a different unique image string */ /* This should get the <img src='../img_T/xxx' /> string as text and store it. */ var $imgSrc        =    $('.displaywrapper img').attr('src');  /* This part should use the above sourced <img src='../img_T/xxx' string and replace ../img_T/ of the src with ../img_L/ and store it in var = imgLink. */ var imgLink        =    $imgSrc.text().replace('img_T','img_L');  /* This part should then wrap the <img src='../img_T/xxx' /> so it becomes <a href='..img_L/xxx'><img src='../img_T/xxx' /></a> */ $('.displaywrapper img').each(function(){.wrap('<a href='imgLink'></a>')}); 

Thanks for reading. Jannis

  • 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. 2026-05-11T06:21:09+00:00Added an answer on May 11, 2026 at 6:21 am

    I think this should do the trick:

    $(document).ready(function() {     $('.displayWrapper img').each(function() {         var src = $(this).attr('src').replace('img_T','img_L');         var a = $('<a/>').attr('href', src);         $(this).wrap(a);     }); }); 

    Line 1: Wait for the document to be ready before doing anything..
    Line 2: Loop through each image using jQuery’s each function.
    Line 3: Get the current image’s src with attr and replace img_T with img_L
    Line 4: Dynamically create a new <a> tag and set it’s href attribute to the src in Line 3
    Line 5: wrap the <a> tag around the <img> tag.

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

Sidebar

Related Questions

Im quite new at Javascript however I have been trying to create a currency
I'm pretty new with installing jQuery plug-ins, and I've only gone so far as
I'm very familiar with HTML and CSS, but new to Javascript and jQuery. I
I am new to rails, and have a situation that I can't quite get
I've been writing C code for quite some time but am very new to
I'm quite new in html5 & js and i have some troubles to develop
I'm working on a Javascript/jQuery powered image preloader, and have hit a bit of
Firstly I am very new to all forms of javascript, particularly anything remotely AJAX.
Hi I am quite new to javascript. So I just tried to create a
I have been working with jquery for a while so this is quite embarrassing

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.