javascript - jQuery selecting and exclude an element inside a div - Stack Overflow

I'm trying to get all the next html code and excluding the DIV with ID=fiscal-address-info using j

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');

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');
Share Improve this question edited Jan 27, 2014 at 21:18 ofimbres asked Jan 27, 2014 at 21:07 ofimbresofimbres 311 silver badge5 bronze badges 1
  • You forgot to post the jQuery you tried. – j08691 Commented Jan 27, 2014 at 21:09
Add a ment  | 

4 Answers 4

Reset to default 5

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.

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

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

Code based on your example:

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

Have a look into this fiddle

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

Gets all div elements and filters them for id #fiscal-address-info Hope this helps!

$('#fiscal-info div').filter(function () {
    return this.id == 'fiscal-address-info'
}).remove();

jsFiddle example

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742287618a4415607.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信