This is a follow-up query for How to get the total instance of the :contains() Selector
I have this array loop issue on getting the total match using contains:selector...
Here are my variables -
var filterarray = ["Content1", "goes"];
<div id="content" style="display:none">Content1 goes here</div>
<div id="content" style="display:none">Content1 goes here too</div>
<div id="content" style="display:none">Content1 goes here again</div>
<div id="content" style="display:none">extra node</div>
Here's my script -
totalSum = 0;
for (i=0;i<filterarray.length;i++){
$( "div[id^=content]:contains('"+ filterarray[i] +"')").css( "display", "block" );
totalSum += $( "div[id^=content]:contains('"+ filterarray[i] +"')").length;
}
$("#results").append("Total Results: " +totalSum);
The results shows = 6, wherein it should only be 3 because the div is already in "block". I think the count goes for each "Content1" = 3 and "goes" = 3, total of 6.
QUESTION: Is there a way to show only 3 and ignore if there are multiple matches (or duplicates) within a DIV instance?