A highly similar question has been asked already, and it has partly solved my problem, but I’d like to know if class or id NAMES can be used in this example instead of ul li – .menu, #menu, etc.
css: div { display:none; background:red; width:200px; height:200px; }
js:
$(function() {
$('ul li').each(function() {
$(this).click(function(e) {
var i = $(this).index();
$('div').hide();
$('div:eq('+i+')').show();
});
});
});
Here’s the jsfiddle for this example: http://jsfiddle.net/Z3Hj7/
Apologies in advance if this question is stupid, but I’ve been mucking about with it for a while and cant figure it out.
Yes, you can:
There is no need at all for using a loop.
Here is a demo