开发者

creating an element and setting its attribute with jQuery

I'm trying to create an <ol> element with jQuery and set its class and id attributes. Is there any way to do this 开发者_如何学编程all at once? None of my ideas have worked so far, I'm still very new to jQuery...


There are at least a couple of different ways to do this:

$('<input id="something" class="something-else" type="text" />')
      .appendTo('#someSelector');

or

$('<input type="text" />').attr('id','something')
                          .addClass('something-else')
                          .appendTo('#someSelector');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜