For the selector, the second parameter must be a jQuery or DOM object. If you provide a string, it will look for the contents of the string. To make it work, you must make the html variable an object:
var html = $('<form action="/" method="get" name="myform"><div>123</div></form>'); console.log($('div', html));
Then, if you want, you can add it to your page:
$('body').add(html);
It is also useful to use the $ for jQuery object variables:
var $html = $('<form action="/" method="get" name="myform"><div>123</div></form>');
So you can easily find out that it is already a jQuery object and you do not need to call ex. $ (html) .show () every time you want to do something about it, you can just call $ html.show ();
source share