0

I have a single page application where a number of fields contain a weight. If the weight is in pounds I want to show it in aquamarine, if in kilograms in yellow. The color to be used is in sUnitColor. All fields containing a weight have a class='weight'. I change colors with:

$('.weight').css('color',sColorUnit);

This works fine throughout the page except within table td cells even though they have class='weight'. They remain unchanged.

Is there something special about table cells that precludes this working?

I've also tried:

$('td .weight').css('color',sColorUnit);

But that doesn't work either.

Any and all suggestions will be much appreciated.

0

2 Answers 2

4

You must not add space between td and .weight as the space is making your selector a Descendant Selector (“ancestor descendant”). The selector td.weight means all tds having class weight.

$('td.weight').css('color',sColorUnit);
Sign up to request clarification or add additional context in comments.

2 Comments

@Amadan explain comment more. it is confusing
@guradio: No need, it served its purpose :) (but if curious, look up s///, then note Adil's edit).
0

If class is in the same element do not use any space between element and class, if a space is there, it means element have a class with that name.

Try with this:

$('element.classname').css({color:sColorUnit});

Comments

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.