I'm looking for the Javascript to parse the following HTML:
<p>random text random text random text random text</p>
<kbd><h2>Heading One</h2>Body text Body text Body text Body text</kbd>
<p>random text random text random text random text</p>
... and return just:
Heading One
In other words, I'd like to strip all tags and Body Text from within the <kbd>
tags.
Any ideas would be greatly appreciated!
Regex?
This matches group one as the shortest possible
(.*?)
string between<h2>...</h2>
.You can find all matches using the
g
option.Note that groups are not accessible.
For multiline content between tags, use
Reference:
document.createElement
innerHTML
element.getElementsByTagName
Node.textContent
(Quirksmode compatibility table)Demo:
if you include jquery (jquery.com) you can do this: