John John
John John

Reputation: 1

Hidding all table that are inside a Div , but only keep one table that comes just before an inner Div

I am working on a web application, and i have a couple of tables that are inside a main Div with ID = ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView. now the main Div have many inner tables and one inner Div. so i need to do the following:-

Here is the markup observed using firefox bug :-

enter image description here

now i have accomplished what i need by doing the following :-

#ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView > table:not(:nth-child(11)) {
    display: none;
}

but this is not very elegant , because if i re-order the folders or add a new folder i need to chnage the nth-child(11). while defining it to hide all the tables except the one that comes before the inner div is more reliable ... Can anyone advice on this? i am using jquery 1.10.2

Upvotes: 0

Views: 72

Answers (3)

anilviradiya
anilviradiya

Reputation: 139

Below code is working for you

inner_div_id:before table {display: none;}

Upvotes: 0

Pete
Pete

Reputation: 58452

var wrapper = $('#ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView'),
    tables = wrapper.children('table');

tables.not(wrapper.children('div').prev()).hide()
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView">
    <table><tr><td>hide</td></tr></table>
    <table><tr><td>hide</td></tr></table>
    <table><tr><td>hide</td></tr></table>
    <table><tr><td>hide</td></tr></table>
    <table><tr><td>show</td></tr></table>
    <div id="tl00_PlaceHolderLeftNavBar_ctl02_WebTreeViewn10Nodes"></div>
    <table><tr><td>hide</td></tr></table>
    <table><tr><td>hide</td></tr></table>
</div>

try this:

Upvotes: 1

azhar_SE_nextbridge
azhar_SE_nextbridge

Reputation: 304

Use this thing.

$("#ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView").nextAll('table').css('display','none');
$("#tl00_PlaceHolderLeftNavBar_ctl02_WebTreeViewn10Nodes").prev('table').css('display','block');

Upvotes: 0

Related Questions