Writing jQuery selector case-insensitive version

前端 未结 3 777
情话喂你
情话喂你 2020-12-06 19:26

I\'m using following line and I would like to make it case-insensitive:

var matches = $(this).find(\'div > span > div#id_to_find[attributeName ^= \"fil         


        
3条回答
  •  醉梦人生
    2020-12-06 19:34

    Here you can see:

    http://www.ericmmartin.com/creating-a-custom-jquery-selector/

    What you have to do is to create a custom jquery selector:

    jQuery.extend(jQuery.expr[':'], {
        exactIgnoreCase: "(a.textContent||a.innerText||jQuery(a).text()||'').toLowerCase() == (m[3]).toLowerCase()"
    });
    

    And then just use it:

    $("#detail select.fields option:exactIgnoreCase(" + q.val() + "):first");
    

提交回复
热议问题