Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Exclude from Jquery Contains Search

Featured Replies

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.