More efficient way to write this Jquery code
Posted
by adamwstl
on Stack Overflow
See other posts from Stack Overflow
or by adamwstl
Published on 2010-04-20T21:10:29Z
Indexed on
2010/04/20
21:13 UTC
Read the original article
Hit count: 128
jQuery
Is there a better, more efficient way to write this code? It's a make shift drop down menu that allows user to RSVP for multiple people. Sorry, it's kind of a mess, but I think what I'm doing is clear. If not, I'm at my computer and will respond quickly with more info need be.
//There's got to be a better way to do this
$('#guest_num_1').click( function() {
$('#num_guests a#quant_guests').html("1")
$('.guest_name_2, .guest_name_3, .guest_name_4, .guest_name_5, .guest_name_6 ').hide()
});
$('#guest_num_2').click( function() {
$('#num_guests a#quant_guests').html("2")
$('.guest_name_2').fadeIn()
$('.guest_name_3, .guest_name_4, .guest_name_5, .guest_name_6').hide()
});
$('#guest_num_3').click( function() {
$('#num_guests a#quant_guests').html("3")
$('.guest_name_2, .guest_name_3').fadeIn()
$('.guest_name_4, .guest_name_5, .guest_name_6').hide()
});
$('#guest_num_4').click( function() {
$('#num_guests a#quant_guests').html("4")
$('.guest_name_2, .guest_name_3, .guest_name_4').fadeIn()
$('.guest_name_5, .guest_name_6').hide()
});
$('#guest_num_5').click( function() {
$('#num_guests a#quant_guests').html("5")
$('.guest_name_2, .guest_name_3, .guest_name_4, .guest_name_5').fadeIn()
$('.guest_name_6').hide()
});
$('#guest_num_6').click( function() {
$('#num_guests a#quant_guests').html("6")
$('.guest_name_2, .guest_name_3, .guest_name_4, .guest_name_5, .guest_name_6').fadeIn()
});
© Stack Overflow or respective owner