|
I've run into a rather interesting, and frustrating bug that I'm hoping someone has some experience with or can help me work around.
Here's the scenario, and I've also set up a fiddle to show it [^]
I have a div with data-location="1"
If I move this div like this
$("#myDiv").appendTo("#someOtherDiv");
and then change the data-location value
$("#myDiv").data("location", "newValue");
I can no longer find the element using the data-location attribute.
This returns 0
$("[data-location='newValue']").length;
This returns 1
$("[data-location='oldValue']").length;
BUT, this returns newValue
$("#myDiv").data("location");
Has anyone ever run into this? Am I missing something here, or doing something wrong?
[EDIT: has some trouble with the fiddle, the link works now.]
[EDIT: SOLVED]
Apparently the .data in jquery only reads the attributes once and never sets the attributes. If you want to set data- attributes and recall them in your code you have to use the .attr() call.
modified 28-Dec-12 10:51am.
|
|
|
|