remove HTML tag - keep everything in between

A

Alexander Paul

Hi!

I'm a newbie to JavaScript who tries to code his first (useful)
Greasemonkey script.

I'd like to do the following:

<p class="someclass">text01 <b>text02</b> text03</p>
=>
<p class="someclass">text01 text02 text03</p>

I tried something like this

var nodes = document.evaluate(
"//p[@class='someclass']/font[1]/text()[1]",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);

for (var i = 0; i < nodes.snapshotLength; i++) {
node = nodes.snapshotItem(i);
s = node.data;
s = s.replace(/<[\b|\B]>/gi,'');
s = s.replace(/<\/[\b|\B]>/gi,'');
node.data = s;
}

Unfortunately, it doesn't work. :(

I would be most grateful for any help or ideas...

Alex
 
M

Martin Honnen

Alexander said:
I'm a newbie to JavaScript who tries to code his first (useful)
Greasemonkey script.

I'd like to do the following:

<p class="someclass">text01 <b>text02</b> text03</p>
=>
<p class="someclass">text01 text02 text03</p>

Grab that p element object and then set
p.textContent = p.textContent;
that way you replace all child elements of p with a single text node
containing the concatenation of all text inside of the element.
With Greasemonkey assuming Mozilla/Firefox this is possible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top