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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:51:28+00:00 2026-05-27T03:51:28+00:00

A newbie question, I obtain a var from a json through a cicle like

  • 0

A newbie question,
I obtain a var from a json through a cicle like this

$.each(json.Links,function(i,link)

I will then append that variable to content using this

$('#content').append('<br>').append(link);

This works, but I also would wish to add to the link an href so that when a user clicks on the link he will be direct to another page but I don’t know how to do this

Edit: Full html and script js

  <!DOCTYPE HTML>
  <html>
<head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="script.js"></script>
    <title>Fake Delicious</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
    <header>
        <!-- Inserir banner -->
        <h1>Delicious Testing Page</h1>
    </header>
    <div id="content">
    coisa
    </div>

</body>
  </html>

Script

 var url="printTables.php?option=6";

 $.getJSON(url,function(json)
  {
  $.each(json.Links,function(i,link)
   { var test="test"+i;
     var but=$("<button>Show info</button>");
     $(link).attr("href", link);
     $('#content').append('<br>').append(link).append($('<div>').append(but));
     });
    })

The button at this stage isn’t suposed to do anything. The link as I said it’s correct since the html shows it properly I just now want to add an hyperlink to it for another page

  • 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-27T03:51:28+00:00Added an answer on May 27, 2026 at 3:51 am

    If you have a variable with a string in it, representing an anchor tag, wrap it with the jQuery function, then save that result. That will give you an actual tag that you can manipulate with jQuery further.

    Then use the attr function to set its href. These steps can be combined.

    This works for me:

    var linkFromJson = "<a>Hello</a>";
    linkFromJson = $(linkFromJson).attr("href", "http://www.google.com");
    
    $("#main").append(linkFromJson);
    

    So for your example, change this:

    $(link).attr("href", link);

    to this:

    link = $(link).attr("href", link);

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

Sidebar

Related Questions

Newbie question. Why is this JavaScript function returning undefined? var redis = require(redis), client
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
Newbie question here. I'd like to be able to specify through data (i.e. an
Newbie question on xslt. I've multiple xsl:if checks like <xsl:if test=node/node1> ...</xsl:if> ... <xsl:if
Flex newbie question: can MXML be generated on the fly, like HTML is generated
newbie question, please forgive... I'm developing a Wpf UserControl that will eventually be bound
Newbie question: I need to accept a parameter in a form from a method
Total newbie question but this is driving me mad! I'm trying this: myInt =
Newbie question i have following function: function isadult($description) { $bad=/*comma separated bad words*/; $bad=explode(,,$bad);
Newbie question... So I have two activities, Cherry and Apple, and each one has

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.