I need to call an object method when a div is clicked...
any idea of how to store the javascript object in the html element?
how to store javascript object in html object?I need to call an object method when a div is clicked...
any idea of how to store the javascript object in the html element? Use a Hash to store the functions, with the keys being the ids. You then use the same id in the div and in the Hash to lookup the required method.
<div id="unique_987">...</div> var MyHash = {}; MyHash["unique_987"] = function(){ alert('yay!'); } Then hook from the on click event. You probably can choose among some variations of this idea. Basically, it's a good idea to keep the HTML elements as pure as possible, see: http://blackbeltcoder.net/2007/04/10/javascript-performance-notes/ alert, I found a solution that looks like that...
function f(obj,elementID) { div1 = ... var x = document.getElementById(elementID); x.appendChild(div1); div1.onmouseover=function(){obj.g();}; } div1 is an element. the element gets the javascript object by the function. later in javascript... <javascript> var x = new object(); x.f(x); what do you think of this solution? Seems like this will be an slow day...
|
|
|
|
|