簡體   English   中英

刪除元素最接近的jquery

[英]removing element closest jquery

我想刪除/隱藏特定范圍內的父元素。 在jquery中這可能嗎?

<body class="page page-id-5269 page-parent page-template-default logged-in kleo-navbar-fixed navbar-resize js" itemtype="http://schema.org/WebPage" itemscope="">
     <p>Your account is not setup as a vendor.</p>
     <form action="" method="POST">
     //....
     </form>
     <br class="clear" style="display: none;">

//other element here that should be display ...

</body>

在上面的代碼我想刪除body標簽內的元素,但直到只在<br class="clear"> 我要刪除的元素是動態生成的,它可以是div,p,span等...目前我有這樣的代碼,但它只會刪除特定的元素(不是動態的):

$('body.page div').first().hide();

請幫忙。 謝謝!

那就是你要隱藏所有以前兄弟姐妹的br.clear元素,這是body.page的孩子所以

$('body.page > br.clear:first').prevAll().hide();

這可能是解決方案:

$('body.page').find('*').each(function(){ //iterating all children 
    $(this).hide();// removing elment
    if($(this).is( "br.clear" ))//checking element is br having class clear
        return false;// breaking loop
});

看DEMO :我沒有使用div.container而是使用了div.container

暫無
暫無

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

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