I have a query into my HTML document using querySelector and querySelectorAll which gets all li ignoring those that has a, here is the code:
var number2 = number;
var otherSubjRow = document.querySelector("#exploreTable");
if(otherSubjRow) {
var otherSubjCells = Row.querySelectorAll("li");
if (typeof(otherSubjCells) != 'undefined' && Cells != null)
{
l = otherSubjCells.length;
var otherSubjects = ""
var number2 = number;
for (var i = 0; i < l; i++) {
if (otherSubjCells[i].querySelectorAll("a").length < 1) {
otherSubjCells[i].innerText + " ");
otherSubjects += number2 + "." + otherSubjCells[i].innerText + " ";
number2++
}
}
}
Here is a snippet of my document:
<table id="exploreTable">
...
<tr>
<li>
<a></a>
</li>
</tr>
<tr><td>
<ul><li>International relations -- Handbook
<a></a>
</li></ul>
</td></tr>
<tr><td>
<ul><li>Titles by: Jose, Charles, editor.
<a></a>
</li></ul>
</td></tr>
<tr><td>
<ul><li>Series: Policy brief ; no. 2016-03
<a></a>
</li></ul>
</td></tr>
</table>
The thing is I want to ignore capturing in my for loop all text that contains in the beginning of the text "Series: " and "Titles by: ". I'm trying it to add it here by using ||:
if (otherSubjCells[i].querySelectorAll("a").length < 1)
But not quite sure if it is the correct way to do it. Or add another if in the statement? Any ideas on how to go about it? Thanks and cheers!
<table id="exploreTable">
<tr>
<li>
<a></a>
</li>
</tr>
<tr>
<td>
<ul>
<li>International relations -- Handbook
<a></a>
</li>
</ul>
</td>
</tr>
<tr>
<td>
<ul>
<li>Titles by: Jose, Charles, editor.
<a></a>
</li>
</ul>
</td>
</tr>
<tr>
<td>
<ul>
<li>Series: Policy brief ; no. 2016-03
<a></a>
</li>
</ul>
</td>
</tr>
</table>
<script>
const arr = document.getElementById("exploreTable").querySelectorAll('li');
const result = [].filter.call(arr,(el)=>{
return !(el.textContent.indexOf("Series:") === 0||el.textContent.indexOf("Titles by:") === 0)
});
const resText = result.map((el, index)=>{
return `${index+1} ${el.textContent}`;
});
console.log(result);
console.log(resText);
</script>