apending to just inserted element
Hi all,
I'm pretty new with jQuery, so I apologize if this is a pretty straightforward issue.
Basically, I am trying to create code that will write a web-widget. So I have:
-
$('<div/>')
.attr('id', 'someId')
.insertBefore(elm);
$('<p/>')
.appendTo('#someId');
This gives an error, but if I change #someId to the id of an element already existing on the screen, things run fine.
I find that I can do
-
$('<div/>')
.attr('id,'someId')
.append('<p/>');
.insertBefore(elm);
And this does pretty much what I want, but it seems like it is going to get super-confusing once things get realistically complex.
Is there a way to get the first example to work, and is there a way I could be doing this better in general?
I really appreciate the help.
-Nicky