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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:34:48+00:00 2026-06-13T23:34:48+00:00

I have this in this var: ver Here i have few lines like this

  • 0

I have this in this var: “ver”
Here i have few lines like this one:

<div class="link" id="1"><a ...>Anchor</a></div>
<div class="link" id="2"><a ...>Anchor 2</a></div>

I search a code in jquery that turn the above code into:

<div class="link" id="1"><a ...><img src="...?anchor=Anchor" /></a></div>
<div class="link" id="1"><a ...><img src="...?anchor=Anchor 2" /></a></div>

What i expect from the code: Find each Anchor – Get it – Generate an image that display this anchor.
PS: I have the function for “Image Generating”.

SOLVED:

$(".link").each(function(){

            anchor =  $(this).find('a').text();
             $(this).find('a').html('<img src="generateLink.php?nr='+encodeURIComponent(anchor)+'" width="39" height="12"/>');  

            });
  • 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-13T23:34:49+00:00Added an answer on June 13, 2026 at 11:34 pm

    I guess the best way to do so is by using a regular expression.

    jQuery('.link').each(function() {
        jQuery(this).html(
            jQuery(this).html().replace(/<a(.*)>(.*)<\/a>/g,
                '<a $1><img src="..?anchor=$2" /></a>')
        );
    });
    

    On the first line you tell jQuery to get each element with the class ‘link’.
    Then you go and find each link inside that element by using ‘/(.*)</a>/g’.

    The first group (a group looks like this: ‘(.*)’) represents the first group we want to capture, because we’ll need the
    information that element is carrying with it.

    The second group is the information we want to store so we know what variable to give our image url.

    At the fourth line we’ll go and replace what we need. Each $-sign followed by a number is a group we’ve captured on the third line.

    If you want to do some testing on regular expressions I can surely recommend http://gskinner.com/RegExr/

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

Sidebar

Related Questions

I have this var var x = <div class=\\\abcdef\\\>; Which is <div class=\abcdef\> But
I have this code: var query = _cityRepository.GetAll( u => u.PartitionKey == pk &
I have this code: var obj = function (i) { this.a = i; this.init
I have this code: var totalAmt=0; for (i in orders) { order=orders[i]; if (order.status
i have this code: var list = new List<int>(); for(int i=0;i<10;i++) list.Add(i); for(int i=0;i<10;i++)
I have this code $('#Submit').click(function(event) { var checked = $('.inputchbox'); ......IE8 var ids= checked.map(function()
I have this code in jquery: var ratio; $(<img/>).attr(src, $(img).attr(src)).load(function() { ratio = this.width
I have this code: var nodeMap:Map[Int, List[Node]] = Map[Int, List[Node]]() nodeMap = Map[Int, List[Node]]()
I have this var in my code: var href = $(this).attr('href'), str = href.split('/').slice(-2,-1)[0];
I have this code: var guestid = $(this).attr('href'); This gets me the current url,

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.