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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:36:32+00:00 2026-06-02T02:36:32+00:00

I am calling a Javascript function from div onClick method <div onClick=sample_1(this) /> from

  • 0

I am calling a Javascript function from div onClick method

<div onClick="sample_1(this)" />

from this sample_1 method i am creating a new div dynamically and adding an onclick event in that div and trying to pass the value of ‘this’ got from the parameter of the sample_1 function but i am not able to pass the value of ‘this’ to the second method:

function sample_1 (divSelected) {
    if (!$(divSelected).attr('disabled')) {
       $('div[id=sample_1]').append("<div id='sample_1_1" + categoryID + "' class='selectedActivityCategory' style='background-color:#d9eaf7;' > <img  src='../Images/close.png' onclick='sample_2(" + divSelected.value + ");' /> </div>");
    }

}


function sample_2(divSelected)
{
/* Some Code */
}

When i am looking into IE developer tool then this dynamic div “sample_1_1” in its onClick method instead of passing the object divSelected value its just writing:

sample_2([object HTMLDivElement]);

How can i pass the object divSelected from sample_1 to sample_2?

I am trying to access the reference of the first div that is calling and passing its reference as this to method sample_1_1 and from there i am creating a new div and onclick event of that created div i am trying to pass the same reference of 1st div to the onclick method of the created div in sample_1_1 method.

  • 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-02T02:36:34+00:00Added an answer on June 2, 2026 at 2:36 am

    I don’t understand what you are trying to do. The regular Javascript this does not have a value property.

    If you are trying to get the contents of the div, you are mixing up this and $(this), because through JQuery you can get the contents of a div (not through value) but by doing $(this).html().

    So a possible solution would be something like:

    <div id="yourdiv">Content...</div>
    
    $(document).ready(function() {
       $('#yourdiv').click(function() {
          sample_1($(this));
       });
    });
    
    function sample_1(div_selected) {
       alert("Contents are: " + div_selected.html());
    }
    

    I made you a small example here…

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

Sidebar

Related Questions

I'm calling a javascript function from a Flex application and it's quite annoying that
This is related to a question I've asked previously: Calling Javascript function after loading
I'm calling the JavaScript function onsubmit of form but form has submit before finished
I have a javascript function for checking errors which I am calling on OnClicentClick
I'm calling a utility called Highslide in a javascript function. Embedding the whole thing
I have a textbox.In its onclick iam calling a javascript fn to call calendar.Texbox
Possible Duplicate: Calling Python from JavaScript I have a test.py and test.js . I
According to this website calling removeChild() in JavaScript causes an Internet Explorer Specific leak
I hate that I'm doing this but I've just started working with Javascript classes
I have a form with onsumbit attribute. I am calling a javascript function on

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.