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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:24:14+00:00 2026-06-15T17:24:14+00:00

I had a click function with jquery which didnt work until I added the

  • 0

I had a click function with jquery which didnt work until I added the ‘event’ (see below).

When is the event needed? This documentation doenst use it: http://api.jquery.com/click/

Didnt work:

$(document).ready(function () {
        $('#div a').click(function () {
            event.preventDefault();
            $('#menu,#wrapper').toggleClass('open');
        });
    })

Works:

$(document).ready(function () {
        $('#div a').click(function (event) {
            event.preventDefault();
            $('#menu,#wrapper').toggleClass('open');
        });
    })
  • 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-15T17:24:15+00:00Added an answer on June 15, 2026 at 5:24 pm

    The documentation you link to precises that the click function is a shortcut for bind with eventType being "click". Here’s an extract of this documentation :

    .bind( eventType [, eventData], handler(eventObject) )

    The prototype of the bind function shows that handler, the callback you provide, receives an eventObject, which is the event you have in your code.

    This event is a jQuery wrapped event, having the function you call, preventDefault.

    So this line

    event.preventDefault();
    

    needs the event to be defined. Writing function(event) in the declaration of your function declares the local variable event whose value will be the one of the eventObject given by jQuery.

    Alternatively, if you don’t like defining variables, you could do this :

    $(document).ready(function () {
        $('#div a').click(function () {
            $('#menu,#wrapper').toggleClass('open');
            return false; // this prevents default handling and also stops propagation
        });
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jQuery code, which works fine: $(document).ready(function () { $('#link1').click(function ()
I'm struggling to determine why the addition of a new jQuery click function is
I'm having trouble getting my callback function to work in post: I've got this
Using jQuery I want to be able to click an element which will also
I've written the JQuery below, and have had to search for items in the
I had image for Products and i want user when click on image appear
I had developed an application for sending email. On click of email button it
I've had quite a few problems with IE6 and our website. http://www.sweetlets.com/w/solutions/click-stream/features/ At the
Had to download Command Line Tools from Apple to get make to work, but
Had a good search here but can't see anything that gets my mind in

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.