簡體   English   中英

如何使用RegEx和Jquery隱藏DIV元素

[英]How to hide a DIV element using RegEx and Jquery

我想在下面隱藏除class="imagebrowser"之外的所有其他元素,

<div class="entry">
    <p>Heading 1</p>
    <p>Heading 2</p>
        ...
    <p>Heading n</p>
    <b>This is abold text</b>
    <div>This is a div element</div>

    <div class="imagebrowser">
        Hello world
    </div>
</div>

預期結果,

<div class="entry">

    <div class="imagebrowser">
        Hello world
    </div>
</div>

請幫忙

嘗試這個

$(".entry").children(":not(.imagebrowser)").hide();
$('div.entry div').not('.imagebrowser').hide();

這將隱藏“entry”div中除了具有“imagebrowser”類之外的所有div。

這段代碼對我有用。 您可以替換$(this).val()#target

$('.'+ $(this).val()).show(); $('.tabcontent2 tr:not(.'+ $(this).val() +')').hide();

你有沒有嘗試過:

$('.entry').children().hide();
$('.imagebrowser').show();

這應該隱藏條目div的所有內容,包括p標簽,然后顯示imagebrowser div。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM