Cris
Cris

Reputation: 437

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!

Upvotes: 1

Views: 57

Answers (2)

Manwal
Manwal

Reputation: 23836

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.

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388396

That is you want to hide all the previous siblings of br.clear element which is a child of body.page so

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

Upvotes: 2

Related Questions