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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:56:08+00:00 2026-05-28T05:56:08+00:00

When using jquery, I have frequently made use of $(this) within events, functions, etc.

  • 0

When using jquery, I have frequently made use of $(this) within events, functions, etc.

Recently I tried the following:

function btn_edit_click (event) {
    alert(event.data.idnum);
}
$(".btn_edit").on("click", { idnum: $(this).attr("title") }, btn_edit_click);

For some reason I get the title of the entire PAGE, rather than the element(s) being referenced by $(".btn_edit"). Am I doing something wrong, or is this expected behaviour?

  • 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-05-28T05:56:09+00:00Added an answer on May 28, 2026 at 5:56 am

    Well it depends what this code is nested within. If the answer is nothing then this refers to the window object.

    If you were referring to this inside an event handler then this would refer to the element on which the event triggered. But it appears as though you are using this in the global space.

    If you want the title of the .btn_edit element to be accessible in the callback function just refer to this in your callback function (notice how it simplifies your code as well):

    function btn_edit_click (event) {
        alert(this.title);
        //UPDATE: I changed $(this).attr('title') to this.title because it performs much faster
    }
    $(".btn_edit").on("click", btn_edit_click);
    

    Here is a demo: http://jsfiddle.net/gRK3z/

    Also here is a performance test to show the difference between using .attr('title') and .title: http://jsperf.com/jquery-attr-title-vs-title

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

Sidebar

Related Questions

using jQuery I have the following code: var selectedIdsArray = $(#selectId option:selected).map(function(){return this.value;}); var
I'm currently using this jQuery Cycle Plugin: http://jquery.malsup.com/cycle/ And I have the following code:
I have been using Jquery alot lately an was wondering if I should use
I have just started using jQuery and although following code gets the job done,
I have started using jQuery and rails. I have made a simple form that
I have a form I am submitting using jQuery's ajaxSubmit function from the Forms
I using jQuery and have the following code, it's a partial and I want
Using jQuery validation plugin but it has no CSV validation. I have made an
I am using jQuery and have server code returning the following values 0:SELECT ONE;1:VALUE1;2:VALUE2
Using jquery I have the function below. When the button is clicked it slides

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.