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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:02:01+00:00 2026-06-13T20:02:01+00:00

I want to click a link and toggle between 2 blocks of content, within

  • 0

I want to click a link and toggle between 2 blocks of content, within a list of content, to essentially go from displaying content to editing content.

I have the following snipits of code:

<style type="text/css">
    div.show {display:block;}
    input.hide {display:none;}
</style>

<script type="text/javascript">
    $(document).ready(function(){
        $('#d-01').on('click', function() {
            $('#d-01-on').toggle();
            $('#d-01-off').toggle();
            $('#d-01-off').focus();
        });
         $('#d-02').on('click', function() {
            $('#d-02-on').toggle();
            $('#d-02-off').toggle();
            $('#d-02-off').focus();
        });
        $('#d-99').on('click', function() {
            $('#d-99-on').toggle();
            $('#d-99-off').toggle();
            $('#d-99-off').focus();
        });
   })
</script>

<a href="#" id="d-01">edit</a>
<div class="show" id="d-01-on">Some content</div>
<input class="hide" id="d-01-off" name="d-01" value="Some content" />

<a href="#" id="d-02">edit</a>
<div class="show" id="d-02-on">Some content</div>
<input class="hide" id="d-02-off" name="d-02" value="Some content" />

<a href="#" id="d-99">edit</a>
<div class="show" id="d-99-on">Some content</div>
<input class="hide" id="d-99-off" name="d-99" value="Some content" />

This works, but I want to make my jquery/javascript code more dynamic and not hard coded. My MySQL table rows will grow over time and I don’t want to have to keep editing my script.

Is it possible to re-write the jquery code to dynamically handle the ID’s rather than having to create individual and redundant on('click', function()‘s?

Thanks for helping.

[see How to Toggle in jQuery for my initial question to this problem]

  • 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-13T20:02:03+00:00Added an answer on June 13, 2026 at 8:02 pm

    I’m not sure if I understanded what you want but here i go:

    First add a div to wrap each repetive section of the HTML markup, in this example I added a class called content-wrapper to add the jquery click event easier:

    <div class="content-wrapper">
        <a href="#" id="d-01">edit</a>
        <div class="show" id="d-01-on">Some content</div>
        <input class="hide" id="d-01-off" name="d-01" value="Some content" />
    </div>
    
    <div class="content-wrapper">
        <a href="#" id="d-02">edit</a>
        <div class="show" id="d-02-on">Some content</div>
        <input class="hide" id="d-02-off" name="d-02" value="Some content" />
    </div>
    
    <div class="content-wrapper">
        <a href="#" id="d-99">edit</a>
        <div class="show" id="d-03-on">Some content</div>
        <input class="hide" id="d-03-off" name="d-03" value="Some content" />
    </div>
    

    Then i modified the JS to the following code:

    <script type="text/javascript">
        $(document).ready(function(){
            $('.content-wrapper a').on('click', function() {
                $(this).siblings().toggle();
                $(this).siblings('input').focus();
            });
       })
    </script>
    

    The JS adds a event to each anchor (a tag) inside the divs of content-wrapper, then when it is clicked, it checks for its siblings (the tags next to it like: div.show and the input) and toggles them. I added a filter in the second siblings to get only the input of the clicked anchor and focus it.

    I didn’t test it but it should work.

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

Sidebar

Related Questions

I want people to click on a link (generated from an asp:HyperlinkField) and have
I want to toggle element that id's pg when click link. header: <title>Example</title> <script
I have some textboxes on a page and I want to click a link
I want to pass a language id for each link i click from my
I want to change my div content on the click of a link, this
Suppose, I want to have a link or a button that when user click
Hello I have the following code: Javascript/jQuery: $(document).ready(function() { $(.clickMe).click(function() { $(.textBox).toggle(); }); });
I want to do something like $('a.filter-link').click(function(e) { e.preventDefault(); var that = $(this), categoryId
Here is what I want to happen: The user should click a link/button that
I want to make a code that counts the click on the link which

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.