Skip to main content
Inspiring
March 16, 2018
Answered

CP9 - How to Show a group of objects?

  • March 16, 2018
  • 1 reply
  • 407 views

CP9

HTML5 only

Hello,

My Question is:

How do I alter the code to Show objects that are currently hidden?

Background:

Following on from this thread:CP9 - Hide a Group using JavaScript - Is there a better solution?

The thread above used code created by TLCMediaDesign and used jQuery to hide objects which have a similar name.

     hideGroup('doctor');

     function hideGroup( which )

     {

     $("*[id*="+ which +"]:visible").each(function()

     {

       cp.hide( $(this).attr( "id" ));

     });

     }

I now need the opposite of this, I want to show the group of objects.

I have looked at the jQuery documentation and it seems to suggest that the opposite of :visible is :hidden.

I changed he code to this, but it did not work.

     $("*[id*="+ which +"]:hidden").each(function()

     {

       cp.show( $(this).attr( "id" ));

What I did discover is that:

     When $(this).attr( "id" ) is used with visible it produces the correct id name, such as doctor.

     When $(this).attr( "id" ) is used with hidden it produces the id name with accStr tagged on the end, such as doctoraccStr.

That seems to be some sort of string error, but I could not find any reference to explain it.

Any help with this would be much appreciated.

Thank you

Peter.

PS This is my first venture in to jQuery, it looks like Egyptian hieroglyphics, but it also looks very interesting in what it can do.

    This topic has been closed for replies.
    Correct answer petern33480613

    Hello,

    I figured it out.

    The HIDE function worked fine, but the SHOW function was tagging the text 'accStr' to the end of the name of the item to show.

    To make the SHOW function work I replaced the 'accStr' with nothing.

    Hope this helps anyone else.

    This is the original function that HIDES items.

         function myHideByName(tmpItemToHide)

         {

         $("*[id*="+ tmpItemToHide +"]:visible").each(function()

         {

         cp.hide($(this).attr("id"));

         });

         }

    This is the function that SHOWS items.

         function myShowByName(tmpItemToShow)

         {

         $("*[id*="+ tmpItemToShow +"]:hidden").each(function()

         {

         // Remove the 'accStr' that gets tagged on to the end of the string.

         var tmpItemToShow = $(this).attr("id").replace("accStr","");

         cp.show(tmpItemToShow);

         });

         }

    Peter

    1 reply

    petern33480613AuthorCorrect answer
    Inspiring
    March 21, 2018

    Hello,

    I figured it out.

    The HIDE function worked fine, but the SHOW function was tagging the text 'accStr' to the end of the name of the item to show.

    To make the SHOW function work I replaced the 'accStr' with nothing.

    Hope this helps anyone else.

    This is the original function that HIDES items.

         function myHideByName(tmpItemToHide)

         {

         $("*[id*="+ tmpItemToHide +"]:visible").each(function()

         {

         cp.hide($(this).attr("id"));

         });

         }

    This is the function that SHOWS items.

         function myShowByName(tmpItemToShow)

         {

         $("*[id*="+ tmpItemToShow +"]:hidden").each(function()

         {

         // Remove the 'accStr' that gets tagged on to the end of the string.

         var tmpItemToShow = $(this).attr("id").replace("accStr","");

         cp.show(tmpItemToShow);

         });

         }

    Peter