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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:29:33+00:00 2026-05-26T10:29:33+00:00

Hi I have a toggle script that works on #toggleshow for the trigger and

  • 0

Hi I have a toggle script that works on #toggleshow for the trigger and #show for the div that displays.

I am using multiple instances of this so I have a script that suffixes numbers at the end of the ID. So I have #toggleshow01, #show01 and so forth.

My script that runs this function is:

$('#toggleshow').live('click', function() {$('#show').slideToggle('slow', function() {});});

The problem is I have to duplicate this script for each instance, ie

    $('#toggleshow').live('click', function() {$('#show').slideToggle('slow', function() {});});
    $('#toggleshow00').live('click', function() {$('#show00').slideToggle('slow', function() {});});
    $('#toggleshow01').live('click',function() {$('#show01').slideToggle('slow', function() {});});
    $('#toggleshow02').live('click',function() {$('#show02').slideToggle('slow', function() {});});
    $('#toggleshow03').live('click',function() {$('#show03').slideToggle('slow', function() {});});

These are the variables I am using to generate the suffixes

var numToggle = 0;
var numShow = 0;        
var toggleTrigger = $('<a id="toggleshow'+ "0" + numToggle++ +'" class="toggle_trigger actions">&nbsp;</a>');
var menuForm = $('<form id="menu_edit_form'+ "0" + numForm++ +'" class="menu_creation_form"></form>');

Please help me to cut this script down to one line if possible.

  • 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-26T10:29:34+00:00Added an answer on May 26, 2026 at 10:29 am

    I personally hate doing things like “toggleshowX” mapping to “showX“. We have much better ways to store data these days. You could for example have your links look like this:

    <a class="toggle_trigger actions" data-target="#show00">&nbsp;</a>
    

    This allows you to get the target based on relevant information using $(this).data('target') in the callback.

    $('.toggle_trigger').live('click', function() {
        var target = $(this).data('target');
        $(target).slideToggle('slow', function() {});
    });
    

    In one line of code:

    $('.toggle_trigger').live('click', function() {$($(this).data('target')).slideToggle('slow', function() {});});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery toggle that animates and displays a DIV. I have a
I have a show/hide toggle working well in multiple instances (thanks to help here
I have got this script that works fine, that allows a user to vote,
I have this little script to toggle a contact form when a button is
I have a div that I want to toggle between displaying or not when
I have this JavaScript on my page to toggle a div and switching between
I have a select all button on this page that works on other browsers
This simple script, to add / delete tablerows using jQuery works well with version
I have a script that works great, but I need the background color to
I have the following code: <script> $(document).ready(function() { $('.toggle_section').click(function(e){ parent = $(e.target).closest(div) objChild =

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.