I have this line in my code:
$(".view" + nodeID).data("urls",viewURLs);
(nodeID is a variable I increment for each element) After that, another element with the same class is added to the DOM. And later on, I have:
alert($(".view" + nodeID).data("urls"));
Which for some reason, displays "undefined". Now my question is: Could it be related to the fact that I added another element with the same class? Does it override the data? I'd expect jQuery to retain data for a class selector, even if its satisfying elements changed. Or am I missing something in the way selectors work? Thanks.
More details: When I set the data, nodeID contains a number which increases each time. Later, on a click event, the ID is extracted from a string that contains it and used in the expression to get the data:
var nodeElement=$(this).closest("table");
if (nodeElement==null) return;
var nodeFullID=nodeElement.attr("id");
var separatorIndex=nodeFullID.indexOf("-");
if (separatorIndex==-1) return;
var nodeID=nodeFullID.substring(4,separatorIndex);
alert($(".view" + nodeID).data("urls"));
Could it be related to the fact that to set the data, nodeID is treated as a number, and then joined to a string to compose the selector, and to get the data, nodeID is extracted from a string?