I have a whole html document in a variable but I don't know how to get the title. Tryied the code below but it only works for specific divs and I don't know why.
//valid html
var data='<!DOCTYPE html><html><head><meta charset="UTF-8" /><title>MyTitle</title><meta name="description" content="MyDEsc" /></head><body><div id="header">header content</div><div class="container" id="wrapper">Default body<div id="home">home</div><div id="project"><div>content</div><div>content</div><div>content</div></div></div></body></html>'
console.log($(data).find('title').text()) //nothing
console.log($('title', $(data)).text()) //nothing
console.log('header :' + $('#header', $(data)).html()) //undefined
console.log('header :' + $('#home', $(data)).html()) //expected value
console.log('project :' + $('#project', $(data)).html()) //expected value
Demo here: http://jsfiddle.net/22RLk/