Reputation: 356
I have a UTF-8 encoded string that contains html markup. I am not able to successfully embed that html into a div using jquery - it always ends up rendering as a string. I am restricted to v 1.7.2 so cant look at parseHTML function.
<div id="target"></div>
<script>
var tgt = $('#target');
tgt.html(resultingCode());
function resultingCode(){
return '%3Ctable%20width%3D%22650%22%20class%3D%22deviceWidth%22%20border%3D%220%22%20cellpadding%3D%220%22%20cellspacing%3D%220%22%20align%3D%22center%22%20bgcolor%3D%22%23eeeeed%22%3E%20%3Ctr%3E%20%3Ctd%20valign%3D%22top%22%20style%3D%22padding%3A0%22%20bgcolor%3D%22%23ffffff%22%3E%20%3Cp%20style%3D%22mso-table-lspace%3A0%3Bmso-table-rspace%3A0%3B%20padding%3A0px%3B%20margin%3A0%3B%22%3E%20%3Ca%20href%3D%22%23%22%3E%3Cimg%20src%3D%22http%3A%2F%2Fplacehold.it%2F650x350%26text%3DFULL%22%20alt%3D%22%22%20border%3D%220%22%20style%3D%22display%3A%20block%3B%20width%3A100%25%3B%20height%3Aauto%3B%22%2F%3E%3C%2Fa%3E%20%3C%2Fp%3E%20%3C%2Ftd%3E%20%3C%2Ftr%3E%20%3C%2Ftable%3E';
}
</script>
A fiddle is here - https://jsfiddle.net/carlv/ocmtaowz/2/
Am stumped - any suggestions most appreciated!
Upvotes: 1
Views: 107
Reputation:
Try making your function resultingCode use decodeURIComponent()
function resultingCode(){
return decodeURIComponent("%3Ctable%20width%3D%22650%22%20class%3D%22deviceWidth%22%20border%3D%220%22%20cellpadding%3D%220%22%20cellspacing%3D%220%22%20align%3D%22center%22%20bgcolor%3D%22%23eeeeed%22%3E%20%3Ctr%3E%20%3Ctd%20valign%3D%22top%22%20style%3D%22padding%3A0%22%20bgcolor%3D%22%23ffffff%22%3E%20%3Cp%20style%3D%22mso-table-lspace%3A0%3Bmso-table-rspace%3A0%3B%20padding%3A0px%3B%20margin%3A0%3B%22%3E%20%3Ca%20href%3D%22%23%22%3E%3Cimg%20src%3D%22http%3A%2F%2Fplacehold.it%2F650x350%26text%3DFULL%22%20alt%3D%22%22%20border%3D%220%22%20style%3D%22display%3A%20block%3B%20width%3A100%25%3B%20height%3Aauto%3B%22%2F%3E%3C%2Fa%3E%20%3C%2Fp%3E%20%3C%2Ftd%3E%20%3C%2Ftr%3E%20%3C%2Ftable%3E");
}
Reference: decodeUriComponent
Upvotes: 1