I have this code:
$(document).ready(function() { //Document Ready
$(".examples .example1").click(function() {
$(".examples .example1 div").fadeToggle("slow");
$(".examples .example1").toggleClass('focused');
});
$(".examples .example2").click(function() {
$(".examples .example2 div").fadeToggle("slow");
$(".examples .example2").toggleClass('focused');
});
$(".examples .example3").click(function() {
$(".examples .example3 div").fadeToggle("slow");
$(".examples .example3").toggleClass('focused');
});
}); // End
This just basically duplicates the same thing on 3 (only 2 in the example below) different elements- Click, Toggle a div, and toggle a class.
Working code here (Ugly and not as It appears in the site- lacking other css/less and images)
This works perfectly, but the (very small) JS person within me says that there must be a cleaner way of doing the same thing? Seems too repetitive and ugly.
Could anyone help to make this better code? (and hence me a better coder if I learn)
examplesXclass. Are there more than one for each?