How do I select a span containing a specific text value, using jquery?

后端 未结 4 1167
悲哀的现实
悲哀的现实 2020-12-28 11:40

How do I find the span containing the text \"FIND ME\"

FIND ME dont find me
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-28 12:05

    By the way, if you'd like to use this with a variable, you'd do it this way:

    function findText() {
        $('span').css('border', 'none');  //reset all of the spans to no border
        var find = $('#txtFind').val();   //where txtFind is a simple text input for your search value
        if (find != null && find.length > 0) {
            //search every span for this content
            $("span:contains(" + find + ")").each(function () {
                $(this).css('border', 'solid 2px red');    //mark the content
            });
         }
    }
    

提交回复
热议问题