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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:53:37+00:00 2026-06-06T12:53:37+00:00

I know the title isn’t the best, I didn’t know how to put this

  • 0

I know the title isn’t the best, I didn’t know how to put this in one sentence.
Anyway, I’ve got some php code creating pairs of links and corresponding boxes which should toggle, when I hit the link. Now I was wondering how you do this in jQuery “the right way”.

Until now I gave every link the class togglelink and an ID togglelink1, togglelink2 etc. The boxes then have the ID togglebox1… So I respond to $(".togglelink").click(), get the current ID, parse the number, add it to the box-ID and toggle the object.

This doensn’t seem very straight foward as it’s a task I’m sure is pretty common. Any suggestions on how I could improve this?

  • 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-06T12:53:38+00:00Added an answer on June 6, 2026 at 12:53 pm

    Depending on how your page is layed out you could use next to find the div to toggle. This way there would be no need for IDs.

    $('.togglelink').click(function() {
        $(this).next('.togglebox').toggle();
    });
    
    <a href="#" class="togglelink">Link 1</a>
    <div class="togglebox">Box 1</div>
    
    <a href="#" class="togglelink">Link 2</a>
    <div class="togglebox">Box 2</div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know the title isn't very clear. I'm new to PHP, so there might
Yes I know, this title isn't really helpfull but this is the exact problem.
The title may sound confusing but it actually isn't, I just didn't know how
I think the title isn't clear enough because I didn't know how to ask
I know the title isn't very elaborate, but I have tried this multiple times
Apologies if the Topic title isn't accurate, I didn't really know how to express
well, i know the title isn't the best, but i'll be as clear as
I know the question title isn't the best. Let me explain. I do a
I don't know which title I should use for this question. I have a
i don't know good title but heres the explain i have this link <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.