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 7061037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:25:30+00:00 2026-05-28T04:25:30+00:00

I am trying to edit a string of HTML (from a textarea) using jQuery.

  • 0

I am trying to edit a string of HTML (from a textarea) using jQuery. When I use this code, links are removed from the resulting string, as expected:

      $('#foo').find('a').remove();
      $('#foo').html(); // links are removed, as expected

But when I use the code below, the links don’t get removed.

      $('#foo').remove('a');
      $('#foo').html(); // links are still there

Why doesn’t this work? I have read the jQuery API documentation for .remove(), and I still don’t understand.

  • 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-28T04:25:31+00:00Added an answer on May 28, 2026 at 4:25 am

    The 'a' selector is a top level filter. It takes the current set, looks for elements that match the selector, and removes them.

    $('#foo').remove('a');
    

    The filter doesn’t search nested elements.

    So if you did this…

    $('.myClass').remove('a');
    

    …and the .myClass selector matched the following elements…

    <p class="myClass">a paragraph</p>
    <a class="myClass">an anchor</a>  <!-- will be removed -->
    <p class="myClass">
        <a>a NESTED anchor</a>
    </p>
    <a class="myClass">an anchor</a>  <!-- will be removed -->
    <a class="myClass">an anchor</a>  <!-- will be removed -->
    <p class="myClass">
        <a>a NESTED anchor</a>
    </p>
    <p class="myClass">a paragraph</p>
    

    …then only the <a> elements at the top level would be removed from the set

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

Sidebar

Related Questions

I am new to jquery. I am trying to parse xml string using jquery.
I'm trying to get the contents of a textarea in an HTML form using
I'm trying to enter edit mode on a specific cell like this: void MainWindow::on_addButton_released()
Im trying to hammer togehter a WYSIWYG-edit in c# following some examples from here
I'm trying to to edit a attribute of all of the special html tags(like
I'm trying to convert a form from synchronous to asynchronous using the Ajax.BeginForm helper
Edit for vhinn I want it to look like this: I am trying to
Trying to pop up an IFrame Shadowbox with Jquery from an asp:gridview datarow. I
I am trying to parse a bit of data from an HTML file, but
I would like to pull artifacts from teamcity. I've been trying to use c#

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.