javascript - Bootstrap nav's background-color not changing when active? -


hi guys when click on bootstrap's nav-bar background-color(of nav bar) not changing according css code. please help!

carousel.js/carousel.css , login.html

$(document).ready(function () {  $('#maincarousel').carousel({  interval: 4000  });    var clickevent = false;  $('#maincarousel').on('click', '.nav a', function () {  clickevent = true;  $('.nav li').removeclass('active');  $(this).parent().addclass('active');  }).on('slid.bs.carousel', function (e) {  if (!clickevent) {    var count = $('#indexmenu').children().length - 1;  var current = $('#indexmenu li.active');  current.removeclass('active').next().addclass('active');  var id = parseint(current.next().data('slide-to'));  if (isnan(id)) {  $('#indexmenu li').first().addclass('active');  }  }  clickevent = false;  });  });
body  {      padding-top: 20px;  }  #mycarousel .nav small  {      display: block;  }  #mycarousel .nav  {      background: #eee;  }  .nav-justified > li >  {      border-radius: 0px;  }  .nav-pills>li[data-slide-to="0"].active { background-color: #16a085; }  .nav-pills>li[data-slide-to="1"].active { background-color: #e67e22; }  .nav-pills>li[data-slide-to="2"].active { background-color: #2980b9; }  .nav-pills>li[data-slide-to="3"].active { background-color: #8e44ad; }
<!doctype html>  <html>  <head>  	<!-- latest compiled , minified css -->  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">  <link rel="stylesheet" type="text/css" href="carousel.css">  <script src="carousel.js"></script>    </head>        <body>  <div class="container">      <div id="mycarousel" class="carousel slide" data-ride="carousel">          <!-- wrapper slides -->          <div class="carousel-inner">              <div class="item active">                  <img src="http://placehold.it/1200x400/16a085/ffffff&text=about us">                  <div class="carousel-caption">                      <h3>                          headline</h3>                      <p>                          lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod                          tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. lorem                          ipsum dolor sit amet, consetetur sadipscing elitr.</p>                  </div>              </div>              <!-- end item -->              <div class="item">                  <img src="http://placehold.it/1200x400/e67e22/ffffff&text=projects">                  <div class="carousel-caption">                      <h3>                          headline</h3>                      <p>                          lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod                          tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. lorem                          ipsum dolor sit amet, consetetur sadipscing elitr.</p>                  </div>              </div>              <!-- end item -->              <div class="item">                  <img src="http://placehold.it/1200x400/2980b9/ffffff&text=portfolio">                  <div class="carousel-caption">                      <h3>                          headline</h3>                      <p>                          lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod                          tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. lorem                          ipsum dolor sit amet, consetetur sadipscing elitr.</p>                  </div>              </div>              <!-- end item -->              <div class="item">                  <img src="http://placehold.it/1200x400/8e44ad/ffffff&text=services">                  <div class="carousel-caption">                      <h3>                          headline</h3>                      <p>                          lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod                          tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. lorem                          ipsum dolor sit amet, consetetur sadipscing elitr.</p>                  </div>              </div>              <!-- end item -->          </div>          <!-- end carousel inner -->          <ul class="nav nav-pills nav-justified">              <li data-target="#mycarousel" data-slide-to="0" class="active"><a href="#">about<small>lorem                  ipsum dolor sit</small></a></li>              <li data-target="#mycarousel" data-slide-to="1"><a href="#">projects<small>lorem ipsum                  dolor sit</small></a></li>              <li data-target="#mycarousel" data-slide-to="2"><a href="#">portfolio<small>lorem ipsum                  dolor sit</small></a></li>              <li data-target="#mycarousel" data-slide-to="3"><a href="#">services<small>lorem ipsum                  dolor sit</small></a></li>          </ul>      </div>      <!-- end carousel -->  </div>        <!-- jquery library -->  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>    <!-- latest compiled javascript -->  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>  </body>        </html>

i think error in css code please let me know! cheers

the id of main container mycarousel , not maincarousel

use

$('#mycarousel').on('click', '.nav a', function () {..}); 

$(document).ready(function () {  $('#mycarousel').carousel({  interval: 4000  });    var clickevent = false;  $('#mycarousel').on('click', '.nav a', function () {  clickevent = true;  $('.nav li').removeclass('active');  $(this).parent().addclass('active');  }).on('slid.bs.carousel', function (e) {  if (!clickevent) {    var count = $('#indexmenu').children().length - 1;  var current = $('#indexmenu li.active');  current.removeclass('active').next().addclass('active');  var id = parseint(current.next().data('slide-to'));  if (isnan(id)) {  $('#indexmenu li').first().addclass('active');  }  }  clickevent = false;  });  });
body  {      padding-top: 20px;  }  #mycarousel .nav small  {      display: block;  }  #mycarousel .nav  {      background: #eee;  }  .nav-justified > li >  {      border-radius: 0px;  }  .nav-pills>li[data-slide-to="0"].active { background-color: #16a085; }  .nav-pills>li[data-slide-to="1"].active { background-color: #e67e22; }  .nav-pills>li[data-slide-to="2"].active { background-color: #2980b9; }  .nav-pills>li[data-slide-to="3"].active { background-color: #8e44ad; }
<!doctype html>  <html>  <head>  	<!-- latest compiled , minified css -->  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">  <link rel="stylesheet" type="text/css" href="carousel.css">  <script src="carousel.js"></script>    </head>        <body>  <div class="container">      <div id="mycarousel" class="carousel slide" data-ride="carousel">          <!-- wrapper slides -->          <div class="carousel-inner">              <div class="item active">                  <img src="http://placehold.it/1200x400/16a085/ffffff&text=about us">                  <div class="carousel-caption">                      <h3>                          headline</h3>                      <p>                          lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod                          tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. lorem                          ipsum dolor sit amet, consetetur sadipscing elitr.</p>                  </div>              </div>              <!-- end item -->              <div class="item">                  <img src="http://placehold.it/1200x400/e67e22/ffffff&text=projects">                  <div class="carousel-caption">                      <h3>                          headline</h3>                      <p>                          lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod                          tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. lorem                          ipsum dolor sit amet, consetetur sadipscing elitr.</p>                  </div>              </div>              <!-- end item -->              <div class="item">                  <img src="http://placehold.it/1200x400/2980b9/ffffff&text=portfolio">                  <div class="carousel-caption">                      <h3>                          headline</h3>                      <p>                          lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod                          tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. lorem                          ipsum dolor sit amet, consetetur sadipscing elitr.</p>                  </div>              </div>              <!-- end item -->              <div class="item">                  <img src="http://placehold.it/1200x400/8e44ad/ffffff&text=services">                  <div class="carousel-caption">                      <h3>                          headline</h3>                      <p>                          lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod                          tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. lorem                          ipsum dolor sit amet, consetetur sadipscing elitr.</p>                  </div>              </div>              <!-- end item -->          </div>          <!-- end carousel inner -->          <ul class="nav nav-pills nav-justified">              <li data-target="#mycarousel" data-slide-to="0" class="active"><a href="#">about<small>lorem                  ipsum dolor sit</small></a></li>              <li data-target="#mycarousel" data-slide-to="1"><a href="#">projects<small>lorem ipsum                  dolor sit</small></a></li>              <li data-target="#mycarousel" data-slide-to="2"><a href="#">portfolio<small>lorem ipsum                  dolor sit</small></a></li>              <li data-target="#mycarousel" data-slide-to="3"><a href="#">services<small>lorem ipsum                  dolor sit</small></a></li>          </ul>      </div>      <!-- end carousel -->  </div>        <!-- jquery library -->  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>    <!-- latest compiled javascript -->  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>  </body>        </html>


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -