I was wondering if anyone knows if its possible to get what the ID of the next LI is with only using the ID of the previous LI.
For exam开发者_Python百科ple
So i would want to be able to go function getNextLI(currentliID){ $(li#currentliID:next-child).animate({ opacity: 1 }); }
All the LI id's won't be in order as they are the item ids coming from the mysql database.
you can use the next()
method of jQuery. For example:
<ul>
<li>...</li>
<li id-"test">...</li>
<li>NEXT</li>
<li>...</li>
</ul>
The following will get you the li
containing the word "NEXT":
var nextSibling = $("li#test").next();
This will fix your problem:
var getNextLI = function(id) {
return $('li#' + id).next('li');
};
var anaimateNext = function(id) {
getNextLI(id).animate({ opacity: 1});
}
You can use jQuery(this).next()
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ol>
jQuery(function(){
jQuery('ol li').bind('click',function(){
jQuery('ol li').css("background-color","#ffffff");
jQuery(this).next().css("background-color","red");
});
});
http://jsfiddle.net/BzFfM/2/
<script>
jQuery(function(){
jQuery('ol li').bind('click',function(){
var s = jQuery(this).next().attr("id");
});
});
精彩评论