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

  • Home
  • SEARCH
  • 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 7813783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:58:55+00:00 2026-06-02T04:58:55+00:00

This question is prob a duplicate (but I can’t find it) so I apologize

  • 0

This question is prob a duplicate (but I can’t find it) so I apologize if it’s redundant. I am trying to use JQuery’s .remove function to allow for removing (obviously) of li elements in my static HTML prototype. Rather than write out a javascript block for each li I want to remove I was wondering if it was possible to create incrementing IDs with JS alone. (I’m using Serve with HAML and SASS fyi). Here is what I have.

/view-file.html.haml

%ul
  %li#removeThis1
    %a.remover1{:src => "#"} Remove

/application.js

...
$(".remover1").click(function () {
  $("li#removeThis1").fadeOut( function() { $(this).remove(); });
});

Any thoughts on how to increment .remover1 to .remover2, etc? Likewise li##removeThis1 to #removeThis2, etc.

I would need all this to happen on page load.

  • 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-02T04:58:56+00:00Added an answer on June 2, 2026 at 4:58 am

    There’s an ancestral relationship between the elements, so just use that to your advantage.

      // don't bother numbering the class. Use a common class
    $(".remover").click(function () {
    
           // find the closest ancestor with an ID that start with "removeThis"
        $(this).closest("li[id^=removeThis]")
               .fadeOut( function() { $(this).remove(); });
    });
    

    Or if you don’t really need an ID on the ancestor, use a class there too…

      // don't bother numbering the class. Use a common class
    $(".remover").click(function () {
    
           // find the closest ancestor with the class "removeThis"
        $(this).closest(".removeThis")
               .fadeOut( function() { $(this).remove(); });
    });
    

    Ultimately, if you were to use IDs, you’d want to generate them on the server side, then extract the numeric portion of the ID from the element with the handler, and concatenate it into the selector for the ancestor.

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

Sidebar

Related Questions

This is prob more of a geometry question, but I have an array of
there. I've searched my question around here but failed to find anything relevant. This
This question has been asked in a C++ context but I'm curious about Java.
This question might look naive, but I couldn't understand this code in the ViewModelLocator.cs
This question has been asked a lot of times in many forums. But I
This question is related to hooking with Mobile Substrate, but as long as you
This question might seem really silly to most of the enlightened folks here. But
Have seen multiple posts on this but I can't see any which answer my
This is may be not program question, but i guess its program logic question.
This question was posted on StackApps , but the issue may be more 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.