Skip to content

Instantly share code, notes, and snippets.

@mgrigajtis
Created December 7, 2012 20:03
Show Gist options
  • Save mgrigajtis/4236084 to your computer and use it in GitHub Desktop.
Save mgrigajtis/4236084 to your computer and use it in GitHub Desktop.
JavaScript function that returns info from between tags (Requires jQuery).
function getTitle(html) {
var strHtml = null;
try {
strHtml = html.replace(/<!\[CDATA\[(.+?)\]\]>/g, function (_match, body) {
return body.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
});
strHtml = strHtml.replace(/<!--.+?-->/g, '');
strHtml = (strHtml.match(/<title>.+?<\/title>/ig) || []);
strHtml = $.map(strHtml, function (t) {
return t.substring(7, t.length - 8);
}).join(' ');
return strHtml;
} catch(ex) {
alert(ex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment