[英]Hide bootstrap element by class that is inside a specific div
I would like to hide the bootstrap multiselect select all button
by the following class: .multiselect-item.multiselect-all
that is inside a specific div(That class is added by bootstrap onto HTML Select
). 我想通过以下类隐藏bootstrap multiselect select all button
: .multiselect-item.multiselect-all
在特定div内(该类通过bootstrap添加到HTML Select
)。 Currently I hide it with javascript
like this: 目前,我用javascript
这样隐藏它:
$('.multiselect-item.multiselect-all').addClass('hidden');
But what that does is it hides that element everywhere on the page. 但是这样做是在页面上各处隐藏了该元素。 I only want hide it in a specified div. 我只想将其隐藏在指定的div中。 I've tried using .parent(), .find(), none which have worked. 我试过使用.parent()、. find(),但没有一个起作用。 Any help is much appreciated. 任何帮助深表感谢。 I use bootstrap multiselect. 我使用引导多选。
My HTML 我的HTML
<select id="typeCheckboxSelect" class="selectpicker" name="typeSelector[]" multiple="multiple">
<option class='typeCheckbox' type='checkbox' value='test1'>Test One</option>
<option class='typeCheckbox' type='checkbox' value='test2'>Test Two</option>
<option class='typeCheckbox' type='checkbox' value='test3'>Test Three</option>
</select>
Multiple select plugin actually hides your original select
element besides its own custom element. 多重选择插件实际上会隐藏其自己的自定义元素之外的原始select
元素。 So, to hide the desired item, you need to modify your selector a bit more: 因此,要隐藏所需的项目,您需要做一些修改:
$('#typeCheckboxSelect ~ div ul li.multiselect-item.multiselect-all').addClass('hidden');
The above selector will only target the Select All button of the multiple select box which is created as a shadow of #typeCheckboxSelect
. 上面的选择器仅定位到作为#typeCheckboxSelect
阴影创建的多重选择框的“ 全选”按钮。
Does Bootstrap add the .multiselect-item.multiselect-all
to the select element? Bootstrap是否将.multiselect-item.multiselect-all
添加到select元素? If so, you can just add the div's class to your jquery selector to target all divs with that specific class name. 如果是这样,您可以将div的类添加到您的jquery选择器中,以使用该特定类名的所有div为目标。
$('.selectpicker.multiselect-item.multiselect-all')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.