I am going to get a element from a html-string with jQuery, but I always get an undefined in my console. My String is:
asd
You can't use jQuery selectors on a collection of nodes like this. You can wrap in a single node to work around this, so just add e.g. a wrapping And then it will work: JSFiddle (remember to view the console to see the log). node.
var htmlBits = ''
+ ' ';
asd fgh jkl '
+ 'console.log($('.test', htmlBits).text()); // outputs 'asd'