I have the following initialized object, and I want to pass this object through onclick function, is this possible to achieve?
var nameObject = { Name: "Stack", lastName:"Exchange" }
Here is my code:
In the document ready I have link with onclick function that is append into html element.
Html:
<div id="test"></div>
Javascript:
$(document).ready(function () {
var nameObject = { Name: "Stack", lastName:"Exchange" };
$("#test").append('<a href="#"'
+'onclick="sendObj(**I want to pass "nameObject" into this function)">'
+'sendObject</a>');
)};
function sendObj(**receive the object**)
{
//nameObject.Name+" "nameObject.lastName;
}