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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:10:39+00:00 2026-05-23T14:10:39+00:00

I have some List items, which contain a div, which contains a link. I’d

  • 0

I have some List items, which contain a div, which contains a link. I’d like to remove this Link from all the divs. This is my current function:

jQuery('.post_meta').each(function(){
    var el = jQuery('.post_meta a');
    el.html(el.html().replace(/, Slider/ig, ""));
});

This function dupolicates one div and add its contents to all the others. What would be the right way?

This is my markup:

<ul>
     <li>
         <div class="post_meta">
         <a href="#">Anything</a>, <a href="#">Slider</a>, <a href="#">Anything2</a> 
         </div>
    </li>
</ul>
  • 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-23T14:10:39+00:00Added an answer on May 23, 2026 at 2:10 pm

    Seems you want something like this:

    $('.post_meta a').filter(function() {
        return $.trim($(this).text()) === "Slider";
    }).remove();
    

    This takes all links inside .post_meta elements and filters them by their content (whether the text is Slider. It then removes those elements.

    Reference: filter, trim, remove

    Update: Regarding your comment. Removing the comma is a bit more tricky, but you can do it like this (after you removed the links):

    $('.post_meta').each(function(){
        $.each($(this).contents(), function() {
            if(this.nodeType === 3) {
                this.nodeValue = this.nodeValue.replace(/,\s*,/g, ',');
            }
        });
    });
    

    It is probably not very performant though…

    Update 2: Apparently removing the comma did not work because after you removed the element node, you have two adjacent text nodes and not one.

    This works though:

    $('.post_meta').each(function(){
        var c = $(this).contents();
        $.each(c, function(i) {
            var prev = c[i-1];
            if(this.nodeType === 3 
               && prev 
               && prev.nodeType ===3
               && $.trim(this.nodeValue) === $.trim(prev.nodeValue)) {
                this.parentNode.removeChild(this);
            }
        });
    });
    

    DEMO

    This basically removes duplicate adjacent text nodes.

    Why am I doing this so complicated?

    Because it looks there might be JavaScript event handlers attached to the links and if you get and set the HTML, these handlers will be lost.

    If this is not the case and the HTML is really like this, you could do:

    jQuery('.post_meta').html(function(i, html) {
        return html.replace('<a href="#">Slider</a>,','');
    });
    

    DEMO 2

    But as said, this only works if (a) the HTML matches exactly with the string and (b) you don’t bind any event handlers to the links (they will be lost).

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

Sidebar

Related Questions

I have some LINQ code that generates a list of strings, like this: var
I have an array List<SomeObject> which contain ascending order of dates (and some more
We have some code which sorts a list of addresses based on the distance
I have some C structures related to a 'list' data structure. They look like
I have a select list with multiple items which I want to be able
I have some SQLAlchemy objects which contain lists of more SQLAlchemy objects, and so
I want to create a list view which contain TextViews that are built from
I'm trying to encode a list of items which have types restricted to be
I have a custom List which carries some attributes I need to serialize along
I have the following cycle in a jspx: <c:forEach var=var items=${dataFile.list.rows}> <li> <div> <a

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.