Monday, November 29, 2010

JQuery insensitive :contains ( find, filter ) how to make as :containsi simple

Энэ код нь том жижиг үсэг ялгахгүй хайлт хийх боломжийг олгох өргөтгөсөн функц юм.

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-1.4.4.js"></script>
</head>
<body>
 
<div>boroo boldbaatar</div>

<div>Harin ene bol minii naiz</div>
<div>Bi bol boroo</div>
<div>B.oroo</div>
     
   
<script>
$.extend($.expr[':'], {
            'containsi': function(elem, i, match, array) {
                //(elem.textContent || elem.innerText || '')
                var val = $(elem).html().toLowerCase();
                var str = (match[3] || "").toLowerCase();
                return (val.indexOf(str) >= 0);
            }
        });
$("div:containsi('boroo')").css("text-decoration", "underline");
</script>
</body>
</html>

No comments: