i have code this:
$(".um").click(function () { $(".subconteudo.dois").slideup(); $(".subconteudo.tres").slideup(); $(".subconteudo.quatro").slideup(); $(".subconteudo.cinco").slideup(); $(".subconteudo.um").slidedown(3000); });
5 more times each of classes(um,dois,...). , i'm trying make smaller code 'this' this:
$(".um, .dois, .tres, .quatro, .cinco").click(function () { $(".subconteudo.um").slideup(); $(".subconteudo.dois").slideup(); $(".subconteudo.tres").slideup(); $(".subconteudo.quatro").slideup(); $(".subconteudo.cinco").slideup(); $(this + ".subconteudo").slidedown(); });
is possible? how? thank way html code this:
<div class="menu"> <div class="submenu um"></div> <div class="submenu dois"></div> <div class="submenu tres"></div> <div class="submenu quatro"></div> <div class="submenu cinco"></div> </div> <div class="conteudo"> <div class="subconteudo um"></div> <div class="subconteudo dois"></div> <div class="subconteudo tres"></div> <div class="subconteudo quatro"></div> <div class="subconteudo cinco"></div> </div>
try solution using filter()
, simple regex (/\b(um|dois|tres|quatro|cinco)\b/g
):
$(".um, .dois, .tres, .quatro, .cinco").click(function () { var firedclass = "."+this.classname.match(/\b(um|dois|tres|quatro|cinco)\b/g)[0]; $(".subconteudo").filter(".um, .dois, .tres, .quatro, .cinco").not(firedclass).slideup(); $(".subconteudo").filter(firedclass).slidedown(); });
it gets menu clicked class through regex. necessary because menu
have more 1 class of list .um, .dois, .tres, .quatro, .cinco
- (if does, picks first found in order: .um
-> .dois
-> .tres
-> .quatro
-> .cinco
, intentional).
also, keep clicked subconteudo
sliding up. (will slide others.)
Comments
Post a Comment