Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery select by inner text

Tags:

jquery

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:

<div class=​"fc-day-number">​1​</div>​

Here is the javascript I have written:

$("div.fc-day-number:contains(" + day + ")").parent().parent().css({ 'background-color': 'Green' });

This will grab all the divs whose inner text contains the day variable, problem is if day==1 then it also selects 11,12,13,21,31,etc. How do I write a JQuery selector that will grab the divs with class "fc-day-number" and whose inner text is exactly equal to day?

like image 926
Joshua Smith Avatar asked Sep 20 '11 13:09

Joshua Smith


2 Answers

Write your own filter function:

$("div.fc-day-number").filter(function (){
    return $(this).text() == day;
}).parent().parent().css({ 'background-color': 'Green' });
like image 125
Dennis Avatar answered Sep 17 '22 08:09

Dennis


$("div.fc-day-number").each(function (){
    if($(this).text()==day)
    {
        $(this).css({ 'background-color': 'Green' });
    }
});
like image 28
Hussam Avatar answered Sep 20 '22 08:09

Hussam