Suppose I wanted to remove any and all text from a web page that did not reside in a specified tag (either a <p> or <h1> tag).
What would be the way to do it?
-MizPippz
Printable View
Suppose I wanted to remove any and all text from a web page that did not reside in a specified tag (either a <p> or <h1> tag).
What would be the way to do it?
-MizPippz
Hi there Ms.Longstocking,
I have just seen this old unanswered post of yours. ;)
Just in case you still require a solution, here it is...
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<style type="text/css">
div {color:#900;}
h1,p {color:#000;}
h2 {color:#909;}
span {color:#009;}
textarea {color:#090;}
.hide{display:none;}
</style>
<script type="text/javascript">
if(window.addEventListener){
window.addEventListener('load',removeElementsText,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',removeElementsText);
}
}
function removeElementsText(){
els=document.body.getElementsByTagName('*');
document.getElementById('but').onclick=function() {
for(c=0;c<els.length;c++) {
if((els[c].tagName!='P')&&(els[c].tagName!='H1')) {
for(d=0;d<els[c].childNodes.length;d++){
if(els[c].childNodes[d].nodeType==3){
els[c].childNodes[d].nodeValue='';
}
}
}
}
document.getElementById('but').className='hide';
}
}
</script>
</head>
<body>
<div>
this text is within a div element
<h1>this text is within an h1 element</h1>
this text is within a div element
<h2>this text is within an h2 element</h2>
this text is within a div element
<p>
this text is within a p element
<span>this text is within a span element</span>
this text is within a p element
</p>
this text is within a div element
<textarea rows="3" cols="30">this text is within a textarea element </textarea>
<button id="but">remove text</button>
</div>
</body>
</html>
Thanks Coothead.
I had already resolved this issue a while back. However, this code will be very useful for another project I am working on.
Cheers,
MizPippz
No problem, you're very welcome. ;)p.s. Have you seen my possible solution to this post of yours...