0

twitter bootstrap carousel not working. I tried changing the id ('#mycarousel') to .carousel or .mycarousel but nothing is working. when I click on the controls it does not advance. what is wrong with this piece of code?

<html>
<head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css"
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js></script>
<script type="text/javascript">
function(){
    $('#mycarousel').carousel();
}
</script>
</head>

<body>
<div class="container">
<div class="row">

<div class="span12 well">
<div id="mycarousel" class="carousel slide span8">
<div class="carousel-inner">
    <div class="item active"><img src="car1.jpg"></div>
    <div class="item"><img src="car2.jpg"></div>
    <div class="item"><img src="car3.jpg"></div>
    <div class="item"><img src="car4.png"></div>
    <div class="item"><img src="car5.jpg"></div>
</div>
<a class="carousel-control left" href="#mycarousel" data-slide="prev">&lsaquo;</a>
<a class="carousel-control right" href="#mycarousel" data-slide="next">&rsaquo;</a>

</div>
</div>

</div>
</div>
<script src="js/carousel.js"></script>
<script src="js/bootstrap-transition.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>
madth3
  • 7,275
  • 12
  • 50
  • 74
SALAMAT Med Ayman
  • 673
  • 1
  • 10
  • 16
  • Do you get any error messages? If you do, please include them in your question or as a comment. – Adam Jul 10 '13 at 17:10

1 Answers1

3

The following code will never gets executed, since you never actually call it.

$('#mycarousel').carousel();

You should change the following:

function(){
    $('#mycarousel').carousel();
}

to:

$(function(){
    $('#mycarousel').carousel();
});

This will make it execute when the dom is ready.

You also do not close you link tag that loads the bootstrap css from being loaded.The following:

<link rel="stylesheet" type="text/css" href="css/bootstrap.css"

Should be:

<link rel="stylesheet" type="text/css" href="css/bootstrap.css" />

You load the JS files in an order which I am not sure if it is correct. I suppose they should be in the reverse order.

Adam
  • 2,204
  • 2
  • 15
  • 15
  • 1
    it still does not work . I also tried a different syntax I so on this website $(document).ready(function(){ $('.carousel').carousel(); }); but it is not working. Can you spot any other problem with this code snippet? – SALAMAT Med Ayman Jul 10 '13 at 21:02
  • I added a little more to my answer. Also, you should open the website were you can access a console to see if there are any error messages when you load the page. You can open the console in chrome with CTRL + SHIFT + J on windows, and CMD + Opt + J on mac. – Adam Jul 11 '13 at 07:07