0

I am trying to something like this:

<a href="www.link.com">JS variable</a>

I have seen multiple threads where someone is trying to do something similar but none of these solutions seem to be working for me. I am trying to pull data from an API and I would like to use a variable from the API as the text for the link. Right now I am using jquery to do this:

$('#tracktitle').append($("<a href='" + track.permalink_url + "' target='_blank'>Title</a><br>").html(track.title));

but would like to have the 'html(track.title)' in place of 'Title'

any help would be greatly appreciated

0

2 Answers 2

3

What about? $('#tracktitle').append("<a href='" + track.permalink_url + "' target='_blank'>" + track.title +"</a><br>")

Sign up to request clarification or add additional context in comments.

Comments

3

When you create a new element with jQuery you can pass just the tag as the first argument to $() and then pass an object with the various properties you want to set as the second argument:

$("<a></a>", {
    href : track.permalink_url,
    html : track.title
}).appendTo("#tracktitle")
.after("<br>");

Demo: http://jsfiddle.net/7CVnZ/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.