Javascript dynamic varible in $.each statement -


I have a catalog of items that all while loop A description of all items, which can be copied with ZeroClipboard plugin.

I need to create the code below for each customer of .itemDescriptionContainer . I so copy the correct data.

I created an attribute with the ID of the item containing the .itemDescriptionContainer


Current code - I tried (and not working)

HTML

  // Loop & lt; Div class = "itemDescriptionContainer" & gt; & Lt; Div id = "copy-button" data-clipboard-target = "copy diploma" & gt; Copy Details & lt; Div & gt; & Lt; Div id = "copyDescription" & gt; & Lt; / Div & gt; // From time to time  

javascript

  $ ("ItemDescriptionContainer"). Each (function (index) {var customer = new ZeroClipboard (document.getElementById ("copy-button"); client.on ("ready", function (readyEvent) {client.on ("aftercopy", function (event) {Event. Target.innerHTML = "Details copied!";});});});  

* The following code is working a bit, it only copies the description of the first item in whileloop

html

  // while loop & lt; Div class = "itemDescriptionContainer" data-itemid = "{{$ item,> id}}}" & gt; & Lt; Div id = "copy-button - {{$ item,> id}}}" data-clipboard-target = "copyDescription - {{$ item,> id}}}" & gt; Copy details & lt; Div & gt; & Lt; Div id = "copyDescription - {{$ item-> ID}}}" & gt; & Lt; / Div & gt; ///>  

JavaScript

  var itemID = $ (this) .attr (' Data-itemid '); // Attach item ID to the client in any way to make a client instance unique. Var client = new gyreclipboard (document.getElementById ("copy-button")); Client.on ("ready", function (ready event) {client.on ("aftercopy", function (event) {event.target.innerHTML = "details copied!";});}); I fixed the problem with the use of the window function, I hope that something can be found. it's helpful.  
  $ ("itemDescriptionContainer"). Each (function () {var itemID = $ (this) .attr ('data-itemID'); // Copy item description var dynamic = window ["client" + idid] = new gyreclipboard (document. Get alimentbiid ("copy -Button- "+IDID"); Dynamic. ("Ready", Function (Ready Event) {dynamic.on ("EntCP" function (event) {event.target.innerHTML = "Details copied!";}); });});  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -