0

I am using

$('div:first', $('#' + id)).css({ 'color': 'red' }) 

to change the color of my div, but it does not work in my page.Then when I get the color by code

$('div:first', $('#' + id)).css('color') 

,it is red! Who can tell me what happened?

I got the right answer about my problem, but it is deleted by someone. I paste it here and hope it can help others.

$('div:first', '[id="' + id + '"]').css({'color': 'red' });

And I will be very thankful if someone can tell me the difference between my code and the answer!

1
  • $('div:first', $('#' + id)).css( 'color', 'red', 'important' ); Commented Apr 12, 2013 at 7:53

3 Answers 3

1

Try this

$('div:first', $('#' + id)).css( 'color', 'red' );
Sign up to request clarification or add additional context in comments.

1 Comment

Can you explain why this is different than just passing JSON data to $.css?
0

Try like $('div:first', $('#' + id)).css('color')

1 Comment

Sorry,it's my fault. I changed the question, and my problem is about set,not get...
0

Try to replace them with

$('div:first', $('#' + id)).css( 'color', 'red' );

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.