JQuery select by inner text

前端 未结 3 1246
我寻月下人不归
我寻月下人不归 2020-12-30 05:19

I am doing a project with fullcalendar and I need to be able to select an element based on the day number. Here is a sample of the element I need to select:



        
相关标签:
3条回答
  • 2020-12-30 05:34
    $("div.fc-day-number").each(function (){
        if($(this).text()==day)
        {
            $(this).css({ 'background-color': 'Green' });
        }
    });
    
    0 讨论(0)
  • 2020-12-30 05:53
    jQuery.expr[":"].text = jQuery.expr.createPseudo(function(arg)
    {
        return function( elem ) {
            return jQuery(elem).text().toLowerCase() == arg;
        };
    });
    

    This code will add the new pseudoselector which will filter elements the internal text which isn't equal to arg. For you example use here so:

    $("div.fc-day-number:text(" + day + ")").parent().parent().css({ 'background-color': 'Green' });
    
    0 讨论(0)
  • 2020-12-30 05:54

    Write your own filter function:

    $("div.fc-day-number").filter(function (){
        return $(this).text() == day;
    }).parent().parent().css({ 'background-color': 'Green' });
    
    0 讨论(0)
提交回复
热议问题