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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:35:47+00:00 2026-06-16T15:35:47+00:00

I am trying to remove an attribute of all elements that match the class

  • 0

I am trying to remove an attribute of all elements that match the class of the child of the element that is clicked on.

for example

<span class="parent">
    <span class="child1">
        <a href="mylink">text</a>
    </span>
</span>

<span class="child1">
    <a href="mylink">text</a>
</span>

I have code that removes the href attribute from the element that is clicked on. However, I would like to be able to also remove any elements that have the same link.

I can of course do this be specifying the specific class, but I want the code to find the class of the child of the parent that is clicked, then find any matching classes and remove the href.

In this case, the person would click on .parent element, the code would search for the class of the child element, .child1, remove the href and also remove the href of any element that also has a matching class of the child element, .child1.

The code would therefore do the same for the following situation

<span class="parent">
    <span class="child2">
        <a href="mylink">text</a>
    </span>
</span>

<span class="child2">
    <a href="mylink">text</a>
</span>

removing the href for all .child2 classes.

The reason for this is because I need to use this functionality many times, and I do not want to have to write different code each time specifying the class for which to remove the href.

I am thinking the construct would be something along the lines of the following, though I am not sure what combinations of jQuery to use to achieve it.

$("parant").click(function () {
    $.find(this.childrenClass, function () {
        $.removeAtt("href");   
    });
});
  • 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-06-16T15:35:48+00:00Added an answer on June 16, 2026 at 3:35 pm

    The code should be self-explanatory:

    $('.parent').click(function() {
        // Get all classes from child elements.
        var classes = $(this).children().map(function() {
            return this.className.split(/\s+/);
        }).get();
    
        // Find any element having one of those classes, find all `a` children
        // and remove the href attribute.
        $('.' + classes.join(',.')).children('a').removeAttr('href');
    });
    

    Here I’m just looking for any element having a class in common with any of the children. You will have to adjust the code to restrict it to certain elements if you want to.

    The code can also be simplified, depending on your actual markup (i.e. if each parent will only have one child or each child only has one class).

    DEMO

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

Sidebar

Related Questions

I want to remove the class attribute from all elements that have an empty
I'm trying to remove all elements that have attribute value that doesn't start with
I'm trying to remove a class attribute from an element and add the class
I'm trying to remove/replace the title attribute on the category elements used by WordPress.
Can someone tell me what I'm doing wrong here. Trying to remove/add class attribute
I am trying to remove the attribute xmlns=http://webdev2003.test.com from the following xml using xsl/xslt,
I'm trying to remove scrollbar from my facebook app. I tried js solution, that
I have a messy html that looks like this: <div id=:0.page.0 class=page-element style=width: 1620px;>
I just spent quite some time trying to remove an attribute with namespace from
I'm trying to allow rel attribute in a elements within HTML Purifier filter. I'm

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.