1

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...

1 Answer 1

3

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');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.