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.
valueproperty. what do you expect to get withdivSelected.value?thisagain, and fetchsample_1by doingdivSelected.parentNode.parentNode.propin place ofattrwhen dealing with boolean attributes. e.g.$(divSelected).prop('disabled').html(<string>)uses string butthisis an object. Why not send id of other div instead ?