2

I'm trying to add css to a 'td' in a Table that is part of the fullcalender

The day cells have classes added fc-day0 to fc-day41
td element looks like this:

<td class="fc-mon fc-widget-content fc-day1">

I tried following:

$("td").filter("fc-day1")
       .css("background", "red");

$("td").find("fc-day1")
       .css("background", "red");

$("td").find($('td[class*=".fc-day1"]'))
       .css("background", "red");

I appreciate your help =)

1
  • just adding a . to your selector before the classname should do the trick (for the first two). as it is jquery things fc-day1 is a tag name... Commented Jul 27, 2012 at 11:29

3 Answers 3

1

if you want to filter out your collection of td and find all who has the class fc-day1 then use filter with a css selector:

$("td").filter(".fc-day1")
    .css("background", "red");
Sign up to request clarification or add additional context in comments.

3 Comments

thx for correctin my code -.-' are there speed differnece between adeno's solution and the filter function? (the class exist only once on the page...)
There is almost certainly no noticeable speed differences but there will be some. Try them both and see which you prefer.
I think adeneo code should be faster (in IE) because both selectors need to go to sizzle anyway and with adeneo´s code it only goes to sizzle once. its an easy miss when you have looked at your code too long @LightMonk ;)
1

To target a TD with the class fc-day1 just do:

$("td.fc-day1").css("background", "red");

FIDDLE

3 Comments

@adeneo: can you tell me how would he apply the red bg color to the classes that start with fc-day? I tried this but it didn't work: jsfiddle.net/Hitman666/XdgSD/2
The starts with selector is ^, but it only mathes if the value of the attribute matches exactly, so it will read all the classes and won't work. You could do this, but that will match if the string of classnames contains that string anywhere, so a filter solution is probably better. For just selecting a classname the regular way, using a filter is completely unnecessary, and I'd go so far as to call it bad practice.
@adeneo: thx! heh, now i think i should have posted this as a question.
0

You don't need jquery.

In a file css:

<style>
table td .fc-day1{
  background:red;
}
</style>

Regards

1 Comment

I ask this question because i have some event calculation in the back ;-) I know how css works =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.