8

I have a jQuery code where I am trying to append to an existing div a label tag which contains a URL. Below is the code:

var strURL = 'http://financials.morningstar.com/ratios/r.htmlt=tup&region=usa&culture=en-US';
var str = '<li>';
str += '<label style="font-family:Arial;">' + strURL + '</label>';
str += '</li>';
$('#existingDiv').append(str);

When the page is actually displayed it shows the URL as:

http://financials.morningstar.com/ratios/r.html?t=tup®ion=usa&culture=en-US

kukkuz
  • 41,512
  • 6
  • 59
  • 95
desiguy
  • 652
  • 2
  • 9
  • 25

1 Answers1

5

A quick fix would be to add the label as a text as a second step after appending the html to the existingDiv - see demo below:

var strURL = 'http://financials.morningstar.com/ratios/r.htmlt=tup&region=usa&culture=en-US';
var str = '<li>';
str += '<label style="font-family:Arial;">' + '</label>';
str += '</li>';
$('#existingDiv').append(str);
$('#existingDiv label').text(strURL);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="existingDiv"></div>
kukkuz
  • 41,512
  • 6
  • 59
  • 95