Muthukamatchi Ganesan
Muthukamatchi Ganesan

Reputation: 373

How to display the value in html page using dom jquery

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

Answers (3)

Akhil Sekharan
Akhil Sekharan

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

Ram
Ram

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

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

Related Questions