Guest User

Untitled

a guest
Apr 27th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. function markMatch(text, term) {
  2. // Find where the match is
  3. var match = text.toUpperCase().indexOf(term.toUpperCase());
  4.  
  5. var $result = $('<span></span>');
  6.  
  7. // If there is no match, move on
  8. if (match < 0) {
  9. return $result.text(text);
  10. }
  11.  
  12. // Put in whatever text is before the match
  13. $result.text(text.substring(0, match));
  14.  
  15. // Mark the match
  16. var $match = $('<span class="select2-rendered__match"></span>');
  17. $match.text(text.substring(match, match + term.length));
  18.  
  19. // Append the matching text
  20. $result.append($match);
  21.  
  22. // Put in whatever is after the match
  23. $result.append(text.substring(match + term.length));
  24.  
  25. return $result;
  26. }
Add Comment
Please, Sign In to add comment