Reputation: 373
I need to display the value in html page using dom jQuery, but its does not display the value. My code:
$(document.createElement("li"))
.append(
$(document.createElement("span"))
.attr({
id: id,
name: name,
value: name
})
)
.addClass('firstli')
)}
Upvotes: 1
Views: 188
Reputation: 12683
Try:
$("<li></li>").append(
$("<span></span>").attr({
id: layer.id,
name: layer.name,
}).text(layer.name)
).addClass('bullet').appendTo(document);
And may be you want to append it to document
Upvotes: 1
Reputation: 144679
span
element doesn't have value
property, you should use text
instead.
var $li = $('<li/>');
$('<span/>', {
id: layer.id,
name: layer.name,
text: layer.name,
'class': 'bullet'
}).appendTo($li)
Upvotes: 1
Reputation: 50563
With your above code you just have created the elements, you still need to add them to the DOM, you have several methods for that, for example you could use .appendTo()
to append your elements at the end of some other existent element in the DOM, so your following line:
).addClass('bullet')
would be changed for this one:
).addClass('bullet').appendTo('#someDOMelement');
Upvotes: 0