0

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?

1
  • checking if url is set first (console.log) shows correct url? Scope of url var is ok? in generated code - what do you see as href=""? Commented Nov 28, 2014 at 6:01

2 Answers 2

2

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>');
Sign up to request clarification or add additional context in comments.

Comments

0

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>"

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.