jQuery: find element by text

后端 未结 7 2250
攒了一身酷
攒了一身酷 2020-11-22 03:31

Can anyone tell me if it\'s possible to find an element based on its content rather than by an id or class?

I am attempting to find

7条回答
  •  我寻月下人不归
    2020-11-22 04:13

    Best way in my opinion.

    $.fn.findByContentText = function (text) {
        return $(this).contents().filter(function () {
            return $(this).text().trim() == text.trim();
        });
    };
    

提交回复
热议问题