If you wanted to use jQuery, the selector of your interest is something like
$('div#parent-container > div').filter(':visible');
For example, if I were to demonstrate the next and previous, I would do it something like this . Using target links, it will work by adding an ID to divs
and referencing the attributes href
for `anchors'. (now included in the example)
Something mess with :
$(function(){
var $divs = $('div > div');
var $selected = 0;
$divs.eq(0).show();
$('#next').click(function(){
$selected = $divs.filter(':visible');
var $next = $selected.next();
toggle($next);
return false;
});
$('#prev').click(function(){
$selected = $divs.filter(':visible');
var $prev = $selected.prev();
toggle($prev);
return false;
});
$('a').click(function(){
$selected = $divs.filter(':visible');
var selector = $(this).attr('href');
if(selector == '#') return false;
toggle( $( selector ) );
return false;
});
var toggle = function($toggle){
if(!$toggle.length) return false;
$selected.hide();
$toggle.show();
}
});
<!--Simple Implementation and dependancies-->
<a id="prev" href="#">Prev</a>
<a id="next" href="#">Next</a>
<a href="#item-4">Show Item Four</a>
<div>
<div id="item-1">One</div>
<div id="item-2">Two</div>
<div id="item-3">Three</div>
<div id="item-4">Four</div>
<div id="item-5">Five</div
<div id="item-6">Six</div>
</div>
div > div {
font-size:5em;
width:auto;
text-align:center;
padding:20px 0;
display:none;
}