1

I have a twitter bootstrap carousel component and I want to detect it's slide function, through that, foreground color of another component should be changed at each slide move.

$('#welcomeCarousel').on('slide',function(e){
   var index = $(this).find('.active').index();       
   if(index==1) {
   $('.navbar-inverse .brand:hover,
      .navbar-inverse .nav > li > a:hover,
      .navbar-inverse .brand:focus,
      .navbar-inverse .nav > li > a:focus').css('color': 'rgb(255, 255, 255)');
   }
});

I think problem occurs because of selecting multiple CSS classes, there should be sth. wrong about it because index has correct value. JS console says unexpected token or unexpected string.

jsfiddle.

3 Answers 3

3

Try this syntax:

.css({'color': 'rgb(255, 255, 255)'});

Documentation: http://api.jquery.com/css/#css-properties

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

1 Comment

Still throws Uncaught SyntaxError: Unexpected token .
0
.css('color': 'rgb(255, 255, 255)');

Should be:

.css('color', 'rgb(255, 255, 255)');

Had you wanted to change multiple css properties, you use this syntax:

.css({'color': 'rgb(255, 255, 255)', diffrentProp : 'SomeValue'});

7 Comments

Still throws Uncaught SyntaxError: Unexpected token .
@ÖmerFarukAlmalı. OH God! You didn't concate the stings in those multiple lines! check out your selector!
OH God! even that throws Uncaught Error: Syntax error, unrecognized expression: unsupported pseudo: hover
@ÖmerFarukAlmalı, Create a jsFiddle.
I've created check question.
|
0

I found a quicker way to do it, first of all, I've defined another CSS class:

.newClass .brand:hover,
.newClass .nav > li > a:hover,
.newClass .brand:focus,
.newClass .nav > li > a:focus {
    color: rgb(255, 255, 255);
}

Then, it is easy to toggle or remove this class:

if(index==1) {
    $('#myNavigationBar').toggleClass("newClass");
}
if(index==0) {
    $('#myNavigationBar').removeClass("newClass");
}

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.