jquery - Group elements to 1 variable to perform different functions on it -
i have list of different elements - e.g. 30 controls , example: lbl1
,lbl2
,lbl3
now i'm sitting ton of duplicated code , difficult maintain e.g.
$("#lbl1,#lbl2,#lbl3").show(); $("#lbl1,#lbl2,#lbl3").attribute('disabled','disabled'); $("#lbl1,#lbl2,#lbl3").hide();
etc there way that
$("#lbl1,#lbl2,#lbl3") = x; x.show(); x.attribute('disabled','disabled'); x.hide();
try
it's attr() not attribute
, better use .prop()
var x = $("#lbl1,#lbl2,#lbl3"); //caching selector x.show(); x.prop('disabled',true); x.hide();
var x = $("#lbl1,#lbl2,#lbl3"); x.show().prop('disabled',true); //you can combine x.hide();
var x = $("#lbl1,#lbl2,#lbl3"); x.show().prop('disabled',true).hide();
Comments
Post a Comment