1

This statement doesnt work:

<script type="text/javascript">

$(document).ready(function () {
    $('p').css( {'color':'Black', 'background-color':'Red'});

<p > DDDDDDDDDDDDDDDDDDDDDDDDDD</p>

why?.. no red background appears!

5 Answers 5

3
$('p').css( {color:'Black', backgroundColor:'Red'});

here is the fiddle http://jsfiddle.net/CAarv/1/

you can use backgroundColor REF or if you want to use background-color use the quotes around them like 'background-color'

   $('p').css( {color:'Black', 'background-color':'Red'});

here is the fiddle http://jsfiddle.net/CAarv/4/

Sign up to request clarification or add additional context in comments.

2 Comments

deleted comment after posting jsfiddle. but @Dmitry whole code is in my answer (with explain)
i thought the OP copied the code from the source so somwhere in his code he might have closed the </script>
2

Maybe tou have error in javascript somewhere and it stops runing ? Or other event overwrite this very fast so you don't see.

Error of parsing - not closed document ready }); in your sample.

Comments

2

You don't appear to have closed your braces. Try the following code

<script type="text/javascript">
$(document).ready(function () {
    $('p').css( {'color':'Black', 'background-color':'Red'});
});
</script>

Comments

1

It works fine

http://sandbox.phpcode.eu/g/8f030.php

<script type="text/javascript">
$('p').css( {'color':'Black', 'background-color':'Red'});
</script>

you have to close <script> and you can remove $(document).ready

1 Comment

Bad practice. You should stay with document ready, it's natural way for starting scripts in jquery. This solution could cause that script will be run late that it can (if lot of loading on page). The problem was unclosed document ready function call.
1

Maybe you have not closed curly brackets? Try this:

$(document).ready(function () {
  $('p').css( {'color':'Black', 'background-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.