Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selecting and exclude an element inside a div

I'm trying to get all the next html code and excluding the DIV with ID=fiscal-address-info using jquery. I started using filter method but no lucky.

This is the original snippet code.

<div id="fiscal-info" class="content-fields">
    <div class="content-title"><h2>Datos Fiscales</h2></div>
    <div class="row">...</div>
    <div class="row">...</div>
    <div class="row">...</div>
    <div id="fiscal-address-info">
    <div class="row">...</div>
    <div class="row">...</div>
</div>

What I'd like to get is:

<div id="fiscal-info" class="content-fields">
    <div class="content-title"><h2>Datos Fiscales</h2></div>
    <div class="row">...</div>
    <div class="row">...</div>
    <div class="row">...</div>
    <div class="row">...</div>
    <div class="row">...</div>
</div>

This is what I've tried:

$('#fiscal-info').filter('#fiscal-address-info');
like image 293
ofimbres Avatar asked Nov 18 '25 16:11

ofimbres


2 Answers

You can use the filter method and using a not selector:

$("#fiscal-info").children().filter(":not(#fiscal-address-info)")

This return you all the fiscal-info children ,except the excluded one.

like image 130
Andrea Parodi Avatar answered Nov 20 '25 05:11

Andrea Parodi


You can use the .not() method or :not() selector

http://api.jquery.com/not-selector/

Code based on your example:

$('div#fiscal-info div').not("#fiscal-address-info");

Have a look into this fiddle

like image 32
Hannan Hossain Avatar answered Nov 20 '25 05:11

Hannan Hossain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!