I’ve created a script that hides a DIV Class if it contains the text "No Event Found" or "Error". This part is working great, however when this happens I would like a hidden DIV ID to load in it’s place. (#brxe-akqmjs)
<script>
const divs = document.getElementsByClassName('etn-not-found-post');
for (let x = 0; x < divs.length; x++) {
const div = divs[x];
const content = div.textContent.trim();
if (content == 'No Event Found' || content == 'Error') {
div.style.display = 'none';
}
}
</script>
How do I go about getting this to load correctly? The DIV I want to show is set to display:none.
Many thanks in advance.
I have tried adding if statements but this only results in the original code breaking.
2
Answers
It depends on how that hidden DIV with ID been implemented.
Let me try to cover two approaches:
display: none;
hidden
For both cases, first get the element reference by ID. For e.g.
Now for case 1,update the style property.
For case 2, set the hidden attribute value to
false
Hope this helps and clarifies your question.
You can simply using jquery
hide()
andshow()
method to hide and show the content. Here I rewrite the function in jquery format.