June 25, 201412 yr Hey guys, I'm stuck and I need some help! LOL How can I make this search function ... exclude content in span tags with the class "excludethis" (<span class="excludethis">Label Title Here</span>) Here is the Javascript: $(".refineSearchInputTextField").keyup(function () { var searchTerm = $(this).val(); var searchItem = $(this).parent().children($("[id^=link_]")); //extends the default :contains functionality to be case insensitive $.extend($.expr[':'], { 'containsi': function(elem, i, match, array) { return (elem.textContent || elem.innerText || '').toLowerCase() .indexOf((match[3] || "").toLowerCase()) >= 0; } }); var searchSplit = searchTerm.replace(/ /g, "'):containsi('") //end of case insensitive chunk //here is the meat. We are searching the list based on the search terms $('[id^=link_]').not(":containsi('" + searchSplit + "')").each(function(e) { //add a "hidden" class that will remove the item from the list $(this).fadeOut( "slow", function() { }); }); //this does the opposite -- brings items back into view $("[id^=link_]:containsi('" + searchSplit + "')").each(function(e) { //remove the hidden class (reintroduce the item to the list) $(this).fadeIn( "fast", function() { }); }); }); Here is the HTML for one of the "Cards" we are iterating through (I've not included the html for the search box as I didn't think it was relavent but it's simply a standard HTML text input with the class of "refineSearchInputTextField".There could be MULTIPLES of these cards showing ... as each card represents an employee in the system. <div class="col-xs-12" id="link_18371"> <div class="metro-block metro-block-atlasblue margin-all-2"> <div class="toolboxtitletext margin-all-8" style="font-size: 25px;"> <p class="toolboxtitletext" >FirstName LastName </p> </div> </div> <div class="metro-block metro-block-lightgray margin-all-2"> <div class="col-xs-12 col-sm-7"> <p class="toolboxtitletext" > <span class="excludethis">Email:</span>info@domain.com </p> <p class="toolboxtitletext" > <span class="excludethis">Category:</span>Owner <span class="excludethis">Employment Type:</span>Employee <span class="excludethis">ID Number:</span>123456 </p> </div> <div class="col-xs-12 col-sm-5"> <a href="xxx" class="excludethis btn btn-large">View</a> </div> </div> </div> So to round up .... I need the Search feature to exclude the information within the spans with the class "excludethis"... so if someone types "Cat" for example it wont show every card because every card has the word "CATagory" ... hope that makes sense
Create an account or sign in to comment