Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding click function to dynamic divs
    text
    copied!<p>There will be number of such div created with unique div id, when i click on click me it should show an alert for that productid, i am doing it like</p> <pre><code>&lt;div id="xyz{productid}"&gt; Click Me &lt;/div&gt; ..... &lt;script type="text/javascript"&gt; var uuid="{productid}" &lt;/script&gt; &lt;script src="file1.js"&gt; </code></pre> <p>code from file1.js</p> <pre><code>$(function () { var d = "#xyz" + uuid; $(d).click(function () { alert("Hello" + uuid); return false; }); alert(d); }); </code></pre> <p>So code is also ok,but the basic problem with it is, since i m doing it on category page where we have number of products,this function is getting bound to last product tile only, I want it to be bound to that specific div only where it is been called </p> <p>.............................. got a solution sorry for late reply,was on weekend holiday, but i solved it by class type of architecture, where we create an object with each tile on page,and at page loading time we initialize all its class vars,so you can get seperate div id and when bind a function to it, can still use the data from its class variables, i m posting my code here so if any one want can use it,</p> <pre><code>UniqeDiv= new function() { var _this = this; var _divParams = null; var _uuid=null; //constructor new function(){ //$(document).bind("ready", initialize); //$(window).bind("unload", dispose); _uuid=pUUID; initialize(); $('#abcd_'+_uuid).bind("click",showRatingsMe) dispose(); } function initialize(){ } function showRatingsMe(){ alert(_uuid); } function dispose(){ _this = _divParams = null } } //In a target file, im including this js file as below &lt;script type="text/javascript"&gt; var pUUID="${uuid}"; &lt;/script&gt; &lt;script type="text/javascript" src="http://localhost:8080/..../abc.js"&gt;&lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload