开发者

jQuery element property

开发者 https://www.devze.com 2023-03-10 00:40 出处:网络
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:

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消