Jquery wild card character

前端 未结 4 487
傲寒
傲寒 2020-12-20 23:39

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

I want to hide these controls.

Currently I am using this:

相关标签:
4条回答
  • 2020-12-21 00:04

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

    $(".controls").hide();
    
    0 讨论(0)
  • 2020-12-21 00:16

    You could use:

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

    or use attributeStartsWith

    0 讨论(0)
  • 2020-12-21 00:19

    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.

    0 讨论(0)
  • 2020-12-21 00:27

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

    $('.controlClass').hide();
    
    0 讨论(0)
提交回复
热议问题