var a = $('<div id="a" />');
a.before($('<div id="b" />'));
console.log(a);
Why do I see the [<div id="a"></div>] as a result and not [<div id="b"></div>,<div id="a"></div>]?
And how to get the expected result (2 objects) in a variable?
UPD:
I already have a so I need to modify it. var a = $('<div id="b" /><div id="a" />'); unfortunately is not a solution
UPD 2:
The sample code above is oversimplified (in comparison to real life application), so in real project it is possible case that both elements don’t have id or any other attribute I can sort by 🙁
That is because
acontains only one element(a). If you want the expected result try thisDemo