$(document).ready(function(){ $(".detail span").click(function() { $(this).prevAll(".mark:last").click(); }); $(".detail > .mark").click(function() { if (this.src.indexOf("closed") != -1) this.src = this.src.replace("closed", "open"); else this.src = this.src.replace("open", "closed"); $(this).nextAll(".details:first").toggle(); }) $(".details").hide(); })