1

I have a div tag as

<div class="one two three">foo<div>
<div class="one two four">bar</div>

i am setting the css by using javascript,I can set styles as

.one.two.three{color:red;}
.one.two.four{color:blue;}

But can any one tell me how can i use $(.class).css({"color":"blue"}); for combination of class

3
  • 3
    $(".one.two.four").css({"color":"blue"}); – what's the problem? Commented Sep 15, 2014 at 13:02
  • @user3567511 show it in a jsfiddle.net, Shai's solution in comment should work Commented Sep 15, 2014 at 13:04
  • Sorry Guys Shai's solution is correct. I was going wrong with case sensitivity. Commented Sep 15, 2014 at 13:12

2 Answers 2

2
  1. Make sure you have loaded jQuery, as the $(selector).css(...) function you say you'd like to use is jQuery-specific.

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    
  2. Set the style – making sure to wait until the DOM is ready before you try manipulating the styles:

    <script type="text/javascript">
        $(document).ready(function() {
            $(".one.two.four").css({"color":"blue"});
        });
    </script>
    

You can read all about everything I've described in the jQuery Getting Started guide.

Working demo: http://jsfiddle.net/4b2n97hq/

If something isn't working, open your browser's console and look for error messages that will help work out the problem.

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

Comments

1

same as with css selector:

$('.one.two.three').css({"color":"blue"});

will select all elements that have all 3 classes.

You can also select just by the classes they have in common:

$('.one.two').css({"color":"blue"});

check this fiddle.

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.