JQuery onclick cleanup function

The code fragment shown below works fine, except that it looks a little amateurish in my opinion (did it myself: P). I am sure it can be much cleaner. So my question is how to combine these "skins"? Any other suggestions?

$('.login_inputbox').removeClass("register_inputbox_error login_inputbox_error").removeClass("register_inputbox_ok login_inputbox_ok");
validator.resetForm();
$(".btn-slide_login").removeClass("active_login");
$(".btn-slide_all").removeClass("active_all");
$('#fancybox-wrap').hide();
$('#fancybox-overlay').hide();
$('#panel_login').hide();
$('#panel_all').hide();

Thanks in advance for your help!

+3
source share
4 answers

To combine operators .hide(), you will need a selector that applies to all four elements. You can do it:

$('#fancybox-wrap,#fancybox-overlay,#panel_login,#panel_all').hide();

Or you can give these elements a common class:

$('.someClass').hide();

Please also note that your first line can be simplified by combining calls .removeClass():

$('.login_inputbox').removeClass("register_inputbox_error login_inputbox_error register_inputbox_ok login_inputbox_ok");
+2
source

removeClass

$('.login_inputbox').removeClass("register_inputbox_error login_inputbox_error register_inputbox_ok login_inputbox_ok");

,

$('.login_inputbox').removeClass("register_inputbox_error login_inputbox_error").removeClass("register_inputbox_ok login_inputbox_ok");

$('#fancybox-wrap, #fancybox-overlay, #panel_login, #panel_all').hide();

$('#fancybox-wrap').hide();
$('#fancybox-overlay').hide();
$('#panel_login').hide();
$('#panel_all').hide();
+5

. ex:

$('#fancybox-wrap, #fancybox-overlay, #panel_login, #panel_all').hide();
+2

If you give #fancybox-wrapyour friends a common class, name it new-class, you can do:

$('.newclass').hide();

and get all four at once.

+1
source

All Articles