Here is a simple HTML code:
<html>
<head>
</head>
<body>
<input id="pathText" type="text" name="Summary" placeholder="Summary"><br>
<input id="groupText" type="text" name="Groups" placeholder="Groups"><br>
<input id="searchButton" type="button" value="Search" onclick="myFunction()"><br>
<table>
<tr>
<details class="mainDetails">
<summary><b>First Summary</b></summary>
<ul>
<details>
<summary><b>Groups</b></summary>
<ul>
<li>group A of First</li>
<li>group B of First</li>
</ul>
</details>
<details>
<summary><b>First People</b></summary>
<ul>
<li>John</li>
<li>Mark</li>
</ul>
</details>
</ul>
</details>
</tr>
<tr>
<details class="mainDetails">
<summary><b>Second Summary</b></summary>
<ul>
<details>
<summary><b>Groups</b></summary>
<ul>
<li>group A of Second</li>
<li>group B of Second</li>
<li>group C of Second</li>
</ul>
</details>
<details>
<summary><b>Second People</b></summary>
<ul>
<li>Alex</li>
</ul>
</details>
</ul>
</details>
</tr>
</table>
<script>
function myFunction(){
var pathString = document.getElementById('pathText').value;
var summariesElements=document.getElementsByTagName("summary");
for(i=0;i<summariesElements.length;i++){
if(summariesElements[i].innerHTML.indexOf(pathString) !== -1){
if(summariesElements[i].parentElement.className === "mainDetails"){
alert(summariesElements[i].parentElement.className);
summariesElements[i].parentElement.style.display = "none";
}
}
}
}
</script>
</body>
</html>
I want to hide the tr
element from details which summary consists String
from pathText
input
.
In my code I know how to get mainDetails
element by using myFunction()
to hide it.
I tried to add class="trClass"
and modify this function to get tr
element and use display="none"
. I use something like:
function myFunction(){
var pathString = document.getElementById('pathText').value;
var summariesElements=document.getElementsByTagName("summary");
for(i=0;i<summariesElements.length;i++){
if(summariesElements[i].innerHTML.indexOf(pathString) !== -1){
alert(summariesElements[i].parentElement.parentElement.className);
if(summariesElements[i].parentElement.parentElement.className === "trClass"){
summariesElements[i].parentElement.parentElement.style.display = "none";
}
}
}
}
But there is a problem because summariesElements[i].parentElement.parentElement
doesn't return the tr
element, it returns just body
.
How can I change my code and use it to hide just tr
from my table
?