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

  • Home
  • SEARCH
  • 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 6857945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:05:44+00:00 2026-05-27T02:05:44+00:00

Is there any way to bind a mouse event such as ‘mouseover’ to a

  • 0

Is there any way to bind a mouse event such as ‘mouseover’ to a JavaScript object?

function test(x,y,z){
   this.x = x;
   this.y = y;
   this.z = z;
   this.add = function(){
       $('body').append("<div id='"+this.z+"'>test: x:"+this.x" y:"+this.y"</div>");
   }
   return this.add();
}

t1 = new test(1,2,3);
t2 = new test(2,3,4);

In my code I have a class/objects defined in the following structure, is there any way to attach a event listener to the appended div, but be able to access the object properties.

  • 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-27T02:05:46+00:00Added an answer on May 27, 2026 at 2:05 am

    You can do this, after you added it to the body, so within your this.add function you can bind your events:

    $("#"+this.z).mouseover(function(){
         // Function
    });
    

    But you know ID’s can’t start with a number right?

    Do this if you want to use this.z. I am using div[0] because all jQuery objects are Arrays, so the 0th element is the element I just created.

    function test(x,y,z){
       var div = $("<div id='"+this.z+"'>test: x:"+this.x+" y:"+this.y+"</div>").appendTo("body");
       div[0].y = y;
       div[0].x = x;
       div[0].z = z;
       div.mouseover(function(){
           alert(this.x);
       });
    
       return div;
    }
    
    t1 = new test(1,2,3);
    t2 = new test(2,3,4);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I bind two event handlers on this link: <a href='#' id='elm'>Show Alert</a> JavaScript: $(function()
Is there any way to bind a DataTable object to an actual table in
I was wondering if there was a way to bind an ArrayList (or any
Is there any way to bind a keyboard shortcut to first option in the
Is there any way to bind a tooltip to a datasource. Here is a
Curious how this could be done. Is there any way to create a delegate
Is there any way that I can bind to a field in a static
Is there any way to bind arguments to slots ala boost::bind ? Here's a
Is there a way to bind a click event to the select options and
Is there any way to properly bind to a Set on a form? I'm

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.