I have the following code that is part of a dynamic loop and creates a new grid with 1 column and 4 rows. The forth row has a button:
var elem = $(this,'a[data-itemid]');
$(elem).prop('data-itemid', '"'+value+'"');
console.log($(elem).prop('data-itemid'));
console.log(elem);
Using developer console, here is how the is drawn:
<a data-role="button" name="orderButton" dsid="orderButton" class="menuMaster_orderButton ui-link ui-btn ui-btn-b ui-icon-none ui-btn-icon-nowhere ui-shadow ui-corner-all" id="menuMaster_orderButton" data-corners="true" data-icon="none" data-iconpos="nowhere" data-mini="false" data-theme="b" tabindex="7" role="button">Order!</a>
As it cycles through each record, I have the above code which should add a new attribute called 'data-itemid' and a value. On this line:
console.log($(elem).prop('data-itemid'));
It gives me the correct value. So I know it's adding the new attribute. But I do not think its adding it to because i cannot find it at all.
console.log(elem);
This gives me :
[Window, jquery: "1.9.1", constructor: function, init: function, selector: "", size: function…]
Which is not the element :(
UPDATE:
This what i am using during the loop as the buttons being created:
$(this,'a[name=orderButton]').data('itemid', value);
This is what is used to fetch it onClick:
console.log('itemid= '+$(this, 'a[name=orderButton]').data('itemid'));
The above comes back undefined.