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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:26:37+00:00 2026-05-24T03:26:37+00:00

I have the following HTML code: <fieldset> <legend><span>Contact Details</span> <span class=edit1>Edit</span><span class=hide1>Hide</span></legend> <div> <!–content–>

  • 0

I have the following HTML code:

            <fieldset>
                <legend><span>Contact Details</span> <span class="edit1">Edit</span><span class="hide1">Hide</span></legend>
                <div>
                <!--content-->
                </div>
            </fieldset>


            <fieldset>
                <legend><span>Contact Details</span> <span class="edit2">Edit</span><span class="hide2">Hide</span></legend>
                <div>
                <!--content-->
                </div>
            </fieldset>  

The spans with the class “hide1” and “hide2” are set to display:none on page load.

Within this code, using jQuery, I am trying to do the following:

  • if edit1 is clicked on, this span becomes hidden, and the associated span with the class “hide1” becomes visible.
  • This should be the same for all other spans in the code e.g. edit2 and hide2. Also if I want to add further edit and hide classes, the function should be able to handle this too e.g. edit3 and hide3 and so on.

So far, I have been able to find the edit span that is clicked on and hide it. I am struggling to get the associated “hide” class. Can anyone help me do this please? Here is my jQuery function so far:

        var spans = $("#myIntForm").find("span[class^='edit'],span[class^='hide']");

        spans.click(function() {
            var $this = $(this);
            spans.filter("span[class^='hide']").hide();
            if($this.attr('class').substr(0,4)=='edit')
                {
                    var visible = $this.filter("span[class^='"+$this.attr('class').substr(0,4)+"']");
                    visible.hide();

                    //find the class 'hide' with same ending number as class 'edit' and display it.
                    var invisible;
                }
        });
  • 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-24T03:26:37+00:00Added an answer on May 24, 2026 at 3:26 am

    I’ve done something similar before, it was easier for me to delimit the classname in some way – i.e an underscore, and also using an ID to help with selecting like so:

    <span class='edit' id='edit_1'>Edit 1</span>
    <span class='hide' id='hide_1'>Hide 1</span>
    

    Then you can find the associated classes like this:

    $(function(){
      $('.hide').hide();
      $('.edit').click(function(){
        //each time an edit class is clicked, show its associated hide div
        var aNum = $(this).attr('id');
        //get the number at the end of the ID of this particular edit div           
        aNum=(aNum.substring(aNum.indexOf('_')+1, aNum.length));
    
        //select and show the associated hide_1 div
        $('#hide_'+aNum).show();
    
        //hide $(this)
        $(this).hide();
      });
    });
    

    I haven’t tested this but you get the idea.
    One other point is that I think you don’t need to assign $(this) to a var, I don’t see anything in your code that would warrant that.

    Hope this helps

    EDIT: Forgot to hide the edit div on click, code updated

    2nd EDIT: Woops, missed a close bracket, also needed a +1 on the substring 🙂 works fine now – got an example up here:
    http://jsfiddle.net/rYMtq/

    A bit irrelevant now that you got an answer but an unclosed bracket is enough to keep me awake at night 😀

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

Sidebar

Related Questions

I have the following HTML code: <div class=container> <span class=red></span> <span class=hot></span> </div> On
I have following HTML code: <section class=indent-1> <!-- Section 1 --> <section> <div>Some content</div>
I have the following HTML on my displayed form <fieldset> <legend>Edit User Roles</legend> <ul>
i have following HTML code:- <table class=results> <tr> <td> <a href=..>link</a><span>2nd Mar 2011</span><br>XYZ Consultancy
I have following HTML code: <div id=wrapper> <div class=page id=first> Test<br/> Test<br/> Test<br/> Test<br/>
I have the following html code: <h3 id=headerid><span onclick=expandCollapse('headerid')>&uArr;</span>Header title</h3> I would like to
I have the following html.erb code that I'm looking to move to Haml: <span
I have the following code in my file to load a div with HTML
I have the following html <div id=menu> <ul class=horizMenu> <li id=active><a href=# id=current>About</a></li> <li><a
I have the following HTML form: <div id=main> <form Id=search-form action=/ViewRecord/AllRecord method=post> <div> <fieldset>

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.