This is a quick one...
Why doesn't it work?
var currentSlideshow = $(".slideshow div").index();
$('#开发者_如何学Cmenu ul li a').click(function() {
alert("currentSlideshow");
});
It won't alert anything.
you are alerting a string "currentSlideshow" instead of a variable currentSlideshow
Your selector is not selecting anything.
#menu ul li a
- Do you have something with id of menu?
- Do you have a
<ul>
as a child the element with id of menu? - Are there
<li>
elements within the<ul>
? - Do the
<li>
elements have<a>
elements?
I rebuild your example: look here there the event fires.
EDIT: pasted the code from jsfiddle
HTML:
<div id="menu">
<ul>
<li><a href="">Test</a></li>
</ul>
</div>
<div class="slideshow" id="4"><div id="5"></div></div>
JS
var currentSlideshow = $(".slideshow div").index();
$('#menu ul li a').click(function() {
alert("currentSlideshow");
});
I would guess that selector never matches an element so the click event is never fired.
Can you post the HTML so we can see if there is a problem there?
As others have suggested please check that the selector is correct. This can be done using firebug, for example.. Try this, add a breakpoint in the handler function, check if it breaks on it.. also, if it is only for the purpose of debugging, use firebug console.
精彩评论