I can't get JQuery's $() element constructor to work right. The following works right (using expect.js for the expect() calls):
var p = $('<div id="1"><div id="2">middle div</div></div>');
expect(p.children('div')).not.to.be(undefined); //passes
expect(p.children('div').attr('id')).to.equal('2'); //passes
But the following doesn't work
var p = $('<p id="1"><div id="2">middle div</div></p>');
expect(p.children('div')).not.to.be(undefined); //passes
expect(p.children('div').attr('id')).to.equal('2'); //fails
Any tips on how to get this to work right?