views:

370

answers:

4

I have 3 controls with id control_1, control_2, control_3.

I want to hide these controls.

Currently I am using this:

$('#control_1').hide();
$('#control_2').hide();
$('#control_3').hide();

Is there a better way of doing this?

Can I do something like $('control_*').hide();?

Is there a way to find controls with start with a specific name?

+3  A: 

Instead, you can set same class to your controls and hide them like that :

$('.controlClass').hide();
Canavar
+3  A: 

Why not replacing IDs with a class like .controls? Then just use:

$(".controls").hide();
Ionuț G. Stan
+5  A: 

For completeness, you can use the starts with attribute filter:

$('[id^="control_"]').hide();

That said, for most purposes it would be better to go with one of the other suggestions.

karim79
+2  A: 

You could use:

$('#control_1,#control_2,#control3').hide();

or use attributeStartsWith

Bavo