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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:49:42+00:00 2026-06-15T23:49:42+00:00

I have a jQuery function inside .click and it does not work. I have

  • 0

I have a jQuery function inside .click and it does not work. I have tested the jQuery and it’s working but have tried multiple combinations as tests inside the .click and things aren’t working correctly for some reason. The console is blank and states there are no erros. It does say, however, that it can’t find any of my defined variables…

html:

<body>
    <section id="container_header">
        <header>
            <nav>
                <a id="home">Home</a>
                <a id="about">About</a>
                <a id="work">Work</a>
                <a id="contact">Contact</a>
            </nav>
        </header>
    </section>
    <section id="container_content">
        <div class="section" id="section-home"></div>
        <div class="section" id="section-about"></div>
        <div class="section" id="section-work"></div>
        <div class="section" id="section-contact"></div>
    </section>

With CSS I am rendering the empty divs and they show properly. Now for the js:

        $(function(){
            $(this).click(function(){
                var pid = $(this).attr("id"); //console says this var is not defined???
                $(this).hide(); //even this does not work???
                //$("div[id^=section-]").hide(); //this works just fine???
                //$(this).closest("#container_header").hide(); //not working???
                //$(this).closest("body").find("#section-" + pid).show(); //no likey???
                //alert("h"); //works
            });
        });

Comments above describe things that work and things that doen’t. It’s probably something stupid but I can’t see it. And yes, while testing I’m removing the comments before trying them.

  • 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-15T23:49:42+00:00Added an answer on June 15, 2026 at 11:49 pm

    Within a ready handler, this is bound to the document itself. Since you wrote:

    $(function() {
        $(this).click(function() {  // Here, 'this' is 'document'.
            var pid = $(this).attr("id");
            $(this).hide();
        }
    });
    

    You’re trying to fetch the id attribute of the document, which does not exist, then to hide the document itself, which cannot be achieved.

    Try matching the <div> elements that expose the section class instead:

    $(function() {
        $("div.section").click(function() {
            var pid = $(this).attr("id");
            $(this).hide();
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery json ajax call and inside my success function I have
I have a jQuery function already to perform the task I need but is
Here's the story... I have a jQuery function that does something, this function is
I have some confusion over a jQuery extension not working as I'd expect. I
I have some jQuery code which works great in Firefox and Chrome, but does
$(function() { $('#<%=btnAdd.ClientID%>').click( { code }); }); The above jquery code I have written
Link to problem : Using .scrollTop() method inside a jQuery Dialog is not working
I've been writing some jQuery functions that have JavaScript variables and looping, etc inside
I have this jquery function that works, except I need to add something. I
I have a jQuery function that replaces thumbnails with the main image. This is

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.