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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:01:27+00:00 2026-06-11T08:01:27+00:00

I need an event handler that is attached to an element, that is invisible

  • 0

I need an event handler that is attached to an element, that is invisible by default.

In there, you can find several jQuery Tabs and the one I’m targeting is also invisible by default.

<div id="help" class="hidden">
     <div id="my-help-tab" class="hidden">
         <div class="targeted">
             <a href="#" class="show-hide">Show</a>
             <pre>test</pre>
         </div>
     </div>
</div>

Now how would I attach an event handler (.toggle() for Show/Hide), that triggers when the element does not have the hidden class (and also it’s child)?

My current solution doesn’t trigger at the first, but only at 2nd or 3rd click.

jQuery( document ).ready( function($)
{
    $( '.targeted' ).on( 'click', function( e )
    {
        event.preventDefault();
        $( this ).children( '.show-hide' ).on( 'click', function( e )
        {
            $( this ).toggle(
                function( e ) 
                {
                    $( this ).html( 'Hide' );
                    $( this ).next( 'pre' ).toggle();
                },
                function()
                {
                    $( this ).html( 'Show' );
                    $( this ).next( 'pre' ).toggle();
                }
            );
        } );
    } );
} );
  • 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-11T08:01:29+00:00Added an answer on June 11, 2026 at 8:01 am

    You can:

    jQuery( document ).ready( function($)
    {
        $('#my-help-tab:not(.hidden) > .targeted > a').on( 'click', function( e )
        {
            event.preventDefault();
            $( this ).children( '.show-hide' ).on( 'click', function( e )
            {
                $( this ).toggle(
                    function( e ) 
                    {
                        $( this ).html( 'Hide' );
                        $( this ).next( 'pre' ).toggle();
                    },
                    function()
                    {
                        $( this ).html( 'Show' );
                        $( this ).next( 'pre' ).toggle();
                    }
                );
            } );
        } );
    } );
    

    Or:

    $('#help:not(.hidden) .targeted > a')
    

    Or (but perhaps unnecessary):

    $('#help:not(.hidden) > #my-help-tab:not(.hidden) > .targeted > a')
    

    Another approach without class:

    $('#my-help-tab:visible > .targeted > a')
    

    You should read these documentations:

    • descendant selector
    • child selector
    • not selector
    • visible selector / hidden selector

    And read this answer for more explanation about descendant vs child selectors.

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

Sidebar

Related Questions

I need an event/events that will do the following: After user selects text/DOM element,
I have to event handlers attached to a form. The first one that fires
I have to event handlers attached to a form. The first one that fires
I need to unit test an event handler that responds to the SerialDataReceived event
In my image's onLoad event handler I need to fetch the URL of the
In the AfterPost event handler for a ClientDataSet, I need the information if the
I need to find which event handlers are registered over an object. For example:
I need a custom event that should raise if a new/existing file in a
I am trying to add a click event on the element that is return
I have an event on one of my classes that I want to attach

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.