Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 782909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:27:39+00:00 2026-05-14T20:27:39+00:00

I’m a little confused about which jQuery method and/or selectors to use when trying

  • 0

I’m a little confused about which jQuery method and/or selectors to use when trying to select an element, and then remove certain descendant elements from the wrapped set.

For example, given the following HTML:

<div id="article">
  <div id="inset">
    <ul>
      <li>This is bullet point #1.</li>
      <li>This is bullet point #2.</li>
      <li>This is bullet point #3.</li>
    </ul>
  </div>
  <p>This is the first paragraph of the article</p>
  <p>This is the second paragraph of the article</p>
  <p>This is the third paragraph of the article</p>
</div>

I want to select the article:

var $article = $('#article');

but then remove <div id="inset"></div> and its descendants from the wrapped set. I tried the following:

var $article = $('#article').not('#inset');

but that didn’t work, and in retrospect, I think I can see why. I also tried using remove() unsuccessfully.

What would be the correct way to do this?

Ultimately, I need to set this up in such a way that I can define a configuration array, such as:

var selectors = [
  {
    select: '#article',
    exclude: ['#inset']
  }
];

where select defines a single element that contains text content, and exclude is an optional array that defines one or more selectors to disregard text content from.

Given the final wrapped set with the excluded elements removed, I would like to be able to call jQuery’s text() method to end up with the following text:

This is the first paragraph of the article.
This is the second paragraph of the article.
This is the third paragraph of the article.

The configuration array doesn’t need to work exactly like that, but it should provide roughly equivalent configuration potential.

Thanks for any help you can provide!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:27:40+00:00Added an answer on May 14, 2026 at 8:27 pm

    I suppose you do not want to modify the original HTML by removing elements from it, but you want to just get the content of article without the inset.
    Thats why I would use clone() to get a copy of the article and then remove the inset from it.

    Like this:

    $("#article").clone().find("#inset").remove().end().text()
    
    • $(“#article”) selects the article div, clone creates a
      copy,
    • find gets the children to
      remove (you could also use children),
    • remove(), removes the selected inset,
    • end() goes back to the original selection.

    At the end I just added text() as you mentioned you wanted to do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.