I'm writing some software that piles HTML fragments and exports them to Microsoft Word. I'd like a script that cycles through the piled fragments and removes certain tags that have a particular class.
I cannot use CSS as the display:none; style doesn't work on export to Word.
I cannot use a tags id as the fragments may have multiple instances of tags I want to hide.
This is what I have so far:
<head>
<script>
function hideme(){
var span = document.getElementById("hideme");
span.parentNode.removeChild(span);
}
</script>
</head>
<body onload="hideme()">
Hello I'd like to remove <span id="hideme" value="1">THIS</span> word, which I can<br/>
I'd also like to remove <span id="hideme" value="1">THIS</span> word, which I can't
</body>
I'm writing some software that piles HTML fragments and exports them to Microsoft Word. I'd like a script that cycles through the piled fragments and removes certain tags that have a particular class.
I cannot use CSS as the display:none; style doesn't work on export to Word.
I cannot use a tags id as the fragments may have multiple instances of tags I want to hide.
This is what I have so far:
<head>
<script>
function hideme(){
var span = document.getElementById("hideme");
span.parentNode.removeChild(span);
}
</script>
</head>
<body onload="hideme()">
Hello I'd like to remove <span id="hideme" value="1">THIS</span> word, which I can<br/>
I'd also like to remove <span id="hideme" value="1">THIS</span> word, which I can't
</body>
Share
Improve this question
asked Aug 1, 2014 at 11:10
Peter J QuinnPeter J Quinn
691 gold badge2 silver badges11 bronze badges
2
- 6 Id should be unique.! – Rajaprabhu Aravindasamy Commented Aug 1, 2014 at 11:10
- $('.className').hide() or $('.className').remove() – Hank Lapidez Commented Aug 1, 2014 at 11:11
2 Answers
Reset to default 4The id need unique, so change id to class
<head>
<script>
function hideme(){
var span = document.getElementsByClassName("hideme");
span.parentNode.removeChild(span);
}
</script>
</head>
<body onload="hideme()">
Hello I'd like to remove <span class="hideme" value="1">THIS</span> word, which I can<br/>
I'd also like to remove <span class="hideme" value="1">THIS</span> word, which I can't
</body>
It very simple with jquery
<body>
Hello I'd like to remove <span class="hideme" value="1">THIS</span> word, which I can<br/>
I'd also like to remove <span class="hideme" value="1">THIS</span> word, which I can't
</body>
script
$(document).ready(function(){
$(".hideme").hide(); //or $(".hideme").remove();
});
using Javascript
you can use:
javascript-remove-element-by-id
using jQuery
:
$('#hideme').hide() // hides element diplay:none
or
$('#hideme').remove() // removes element