sierre

Inline Search Bar - ELEMENTOR

Jan 11th, 2026
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.88 KB | None | 0 0
  1. <style>
  2. /* Search Box Style */
  3. #inPageSearch {
  4.     width: 100%;
  5.     padding: 15px;
  6.     border: 1px solid #ddd; /* Light grey border */
  7.     background: #fff;
  8.     font-size: 16px;
  9.     border-radius: 6px;
  10.     margin-bottom: 20px;
  11.     box-sizing: border-box; /* Ensures padding doesn't break layout */
  12. }
  13.  
  14. /* "No Results" Message Style */
  15. #noResultsMsg {
  16.     display: none; /* Hidden by default */
  17.     color: #666;
  18.     font-style: italic;
  19.     margin-bottom: 20px;
  20. }
  21. </style>
  22.  
  23. <input type="text" id="inPageSearch" placeholder="Search authors...">
  24.  
  25. <div id="noResultsMsg">No authors found matching your search.</div>
  26.  
  27. <script>
  28. jQuery(document).ready(function($) {
  29.    
  30.     $('#inPageSearch').on('keyup', function() {
  31.        
  32.         var searchTerm = $(this).val().toLowerCase();
  33.         var matchCount = 0;
  34.         var hasSearchTerm = searchTerm.length > 0;
  35.  
  36.         // 1. Loop through every element that has the class 'author-container'
  37.         $('.author-container').each(function() {
  38.            
  39.             // 2. Get all text inside this specific container
  40.             // We use $(this).text() so it grabs headings, paragraphs, buttons - everything inside.
  41.             var containerText = $(this).text().toLowerCase();
  42.            
  43.             // 3. Check if the search term exists inside that text
  44.             if (containerText.indexOf(searchTerm) > -1) {
  45.                 $(this).show(); // Match found, ensure it is visible
  46.                 matchCount++;
  47.             } else {
  48.                 $(this).hide(); // No match, hide the whole container
  49.             }
  50.         });
  51.  
  52.         // 4. Handle "No Results" message
  53.         // If we typed something AND found 0 matches, show the message
  54.         if (hasSearchTerm && matchCount === 0) {
  55.            $('#noResultsMsg').show();
  56.         } else {
  57.             $('#noResultsMsg').hide();
  58.         }
  59.     });
  60. });
  61. </script>
Advertisement
Add Comment
Please, Sign In to add comment