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');
精彩评论