473,322 Members | 1,566 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

remove HTML tag - keep everything in between

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</btext03</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

Nov 28 '06 #1
2 2090
Alexander Paul wrote:
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</btext03</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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 28 '06 #2
Hi!

Thank you very much for your reply!

It works perfectly! :)

Alex.

Nov 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DesignGuy | last post by:
I need to replace everything between and including two snippets of HTML code, for example: </table></td></tr></table> klsdjff sd fsd fs fs df sdfs df sdf sd fsf d <B><P> sfd sd fsdfs <br> ...
7
by: Robert Oschler | last post by:
Is there a module/function to remove all the HTML entities from an HTML document (e.g. - &nbsp, &amp, &apos, etc.)? If not I'll just write one myself but I figured I'd save myself some time. ...
4
by: Nico Grubert | last post by:
Hello, I want to remove all html tags from a string "content" except <a ....>xxx</a>. My script reads like this: ### import re content = re.sub('<((|\n)*)>', '', content)
1
by: Mitchua | last post by:
I am trying to use HTML::Parser to parse an HTML file, remove all HTML tags (including comments, etc.), replace all ENTITIES (e.g. &amp), and put the result into a variable as a string. I figure...
14
by: j1c | last post by:
How can I remove the content in between tags? I have a page that has several custom tags: <!--tag:1--> Content 1 <!--/tag:1--> <br> <!--tag:2--> Content 2 <!--/tag:2--> <br> <!--tag:3--> Content 3...
1
by: prakash280681 | last post by:
how to get the correct result when we parse the xml code.Because in parsing when it get the syntax like < and & it break it and forward.. i use the code---- <?php $xml_file = "news.xml"; ...
2
by: mdaWeb335 | last post by:
Hi I'm trying to use RegEx to remove a tag by it's ID attribute. The actual HTML has already been cleaned up as I am formatting for export to Excel (so no need to point out that it's incorrect...
2
by: Sjef | last post by:
Hallo there, I am trying to create an webpage where everything is set in tabbed pages. I have a testpage set here: http://www.art-trade.nl/reunie/pages/testpagina.html In IE6 the thumbnails are...
1
by: Cilla | last post by:
I have problem keeping the formatting of the XML elements when reading a file and writing it back, When reading the XML document I'm using XML document ( XmlDocument.Load (String) ), with...
2
by: Edan | last post by:
Hello I'm trying to remove square brackets and everything between them from a string, using regular expressions I know how to use preg_replace, and know the basics of regex, but can't success....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.