user3145095
user3145095

Reputation: 63

how to add url from json data in the href tag in javascript

i have a url value from the json response which is like

url=response.url.urlname;(//suppose this contains the value like www.google.com)

now i want to include it in anchor tag in my javascript code web is div in html page

<div id="web>
$("#web").append('<a href="http://"'+url+'"" rel="external" data-direction="reverse">'+url+'</a>');

i am unable to load the page.can anybody help me for this concatenation?

Upvotes: 0

Views: 5781

Answers (2)

Eric Herlitz
Eric Herlitz

Reputation: 26277

Seems as you are using bad quotation

var url = "www.google.com"
var link = '<a href="http://"'+url+'"" rel="external" data-direction="reverse">'+url+'</a>'
// returns: "<a href="http://"www.google.com"" rel="external" data-direction="reverse">www.google.com</a>"


var url = "www.google.com"
var link = '<a href="http://'+url+'" rel="external" data-direction="reverse">'+url+'</a>'
// returns: "<a href="http://www.google.com" rel="external" data-direction="reverse">www.google.com</a>"

Upvotes: 0

codingrose
codingrose

Reputation: 15699

It seems that you have not used quotes properly.

Try this:

$("#web").append("<a href='http://"+url+"' rel='external' data-direction='reverse'>"+url+"</a>");

OR this:

$('#web').append('<a href="http://'+url+'" rel="external" data-direction="reverse">'+url+'</a>');

Upvotes: 2

Related Questions