elementzero23 elementzero23 - 1 year ago 119
HTML Question

jQuery append() not working for concatenated String

(Full code below)


$('#' + id).parent().append('<div id="pop-up">hello</div>');

does work. But this

$('#' + id).parent().append('<div id="pop-up-' + id + '">hello</div>');


The fact that the first version works lets me assume that the problem is not the

So the full code is

function clickOnElement(id) {
var obj = {};
obj.clicked = String(id);
var jsonData = JSON.stringify(obj);
type: 'POST',
url: '../db/RequestHandler.ashx',
data: jsonData,
contentType: 'application/json; charset-utf-8',
success: function (response) {
// Add the div for the dialog-box
$('<div>Hello</div>', {
"id": "pop-up" + id
}).appendTo($('#' + id).parent());
error: function () {
console.log("request error");

Answer Source

Try the following

var parent = $('#' + id).parent();
var el = $('<div>', {id: "pop-up"+id,text:"hello"});

the proper way to add text to a created object is to use the text property:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download