简体   繁体   中英

removing element closest jquery

I want to remove/hide the element inside the parent in specific range. Is that possible in 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>

on the code above i want to remove element inside the body tags but until in <br class="clear"> only. The element that i want to remove is dynamically generated it can be div, p, span, etc... Currently i have code like this but it will remove only the specific element (not dynamicaly):

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

Please help. Thank you!

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

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

This might be solution:

$('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
});

See DEMO : Instead of using body i have used div.container .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM