I'm trying to get the content between 2 strings and do operation on them. For example here you can see there are two $toc variables. I want to get the content between these two and make a table of content based on that. If you see the fiddle link you'll see that it's taking all the h1,h2,h3,h4 tags and making table of content by replacing first $toc but I don't want all the H tags in that table of content. I want just the H tags between these two $toc strings. How can I do that?
What I tried
function createTOC(elements) {
var tocString = '';
for (var i = 0, len = elements.length; i < len; i++) {
tocString += elements[i].outerHTML;
}
var $body = $('body');
var html = $body.html();
var newHtml = html.replace('$toc', tocString);
$body.html(newHtml);
}
var $tocElements = $('h1, h2, h3, h4');
createTOC($tocElements);
ptags with$tocinside... Just wrap what you need in a container, and take the children headings. Extradivwon't break your layout, it doesn't have any default styles.