jQuery element property
is there a way to create/add multiple elements at once? In the following example I would like span an开发者_JS百科d ul to be both innerHTML properties of li:
jQuery('<li/>', {
html: jQuery('<span/>', {
text: 'a',
}), jQuery('<ul/>', {
text: 'b',
})
}).appendTo("#t");
I would like to do it in one call, without having to pass a string of HTML (which I did before).
Thanks
You could do:
jQuery('<li/>')
.append(jQuery('<span/>', {text: 'a'})
.append(jQuery('<ul/>', {text: 'b'})
.appendTo("#t");
精彩评论