(function ($, Drupal) { Drupal.behaviors.myCustomBehavior = { attach: function (context, settings) { // Get all divs within the 'views-field-nid-1' class. var codeDivs = $('.views-field.views-field-nid-1 div'); // Loop over each div. codeDivs.each(function() { // Get the ID of the current div. var divId = $(this).attr('id'); // Extract the node ID from the div ID. var nodeId = divId.replace('code', ''); // Generate and append the QR code to the current div. if(nodeId) { $(this).qrcode("releaf.site/node/" + nodeId); } }); // Get all divs with an id starting with 'waste'. var wasteDivs = $('div[id^="waste"]'); // Loop over each div. wasteDivs.each(function() { // Get the ID of the current div. var divId = $(this).attr('id'); // Extract the waste ID from the div ID. var wasteId = divId.replace('waste', ''); // Generate and append the QR code to the current div. if(wasteId) { $(this).qrcode("releaf.site/taxonomy/term/" + wasteId); } }); } }; })(jQuery, Drupal);