The example in this article describes how jQuery implements the contains method to be case-insensitive. Share it with everyone for your reference. The specific implementation method is as follows:
// NEW selector jQuery.expr[':'].Contains = function(a, i, m){ return jQuery(a).text().toUpperCase() .indexOf(m[3].toUpperCase()) >= 0; }; // OVERWRITES old selecor jQuery.expr[':'].contains = function(a, i, m){ return jQuery(a).text().toUpperCase() .indexOf(m[3].toUpperCase()) >= 0; };
Usage:
$("div:contains('John')")
Test HTML file:
<div>john</div> <div>John</div> <div>hey hey JOHN hey hey</div>
I hope this article will be helpful to everyone’s jQuery programming.