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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:58:21+00:00 2026-06-14T00:58:21+00:00

With this example 1 $(#my_div).on(click, function () { alert( $(this).attr(id) ) }); we obtain

  • 0

With this

example 1

$("#my_div").on("click", function () {
    alert( $(this).attr("id") )
});

we obtain correct result, but if I use this:

example 2

function thisId () {
    alert( $(this).attr("id") )
}

$("#my_div").on("click", function () {
    thisId();
});

Now the result is undefined. Please tell me how I should be using this, when the selector and function using this are written as different expressions, as in example 2?

  • 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-14T00:58:22+00:00Added an answer on June 14, 2026 at 12:58 am

    For jQuery to pass the element reference to the function you must provide the function as a reference. Try this:

    $("#my_div").on("click", thisId);
    

    Update for @bot

    function thisId (event) {
        alert( $(this).attr("id") )
        alert(event.type);
    }
    
    $("#my_div").on("click", thisId);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my code: $('div.menu > ul > li > a').click(function(e) { alert($(this).eq()); e.preventDefault(); });
thank you for looking i got this example from my book but i cant
This example is simplified a bit, but in my ASP.NET web page in my
I have generated few elements in my page using following method. For example, $(#button+caption).click(function(){
I need to have a for loop inside my jQuery. Example: for(i=0;i<counter;i++) { $("div"+i+"").click(function(){//some
Consider the following code: <div id=outer> <div id=inner></div> </div> $('#outer').click(function() { alert (outer); });
In this example my NSDictionary initializes with 0 key/value pairs, as shown in my
In this example below: my $rs = $schema->resultset('CD')->search( { 'artist.name' => 'Bob Marley' 'liner_notes.notes'
I managed to apply this excellent example to my needs: http://code.google.com/p/galleriffic/issues/attachmentText?id=76&aid=-3045121742886940548&name=example-2.html&token=4nlvmgAfVpc5whcXC9UEqHZaSz0%3A1339257750721 With a small
This is my example of my table: id | name | foreign_id | -------------------------

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.