I’m trying to use $.data() for the first time. I want to store some data…append that data to a label but I don’t know if this $.data() can be used to append to ANY DOM element such as labels, you name it or only to elements such as divs and specific elements like that.
$('#myLabelID').data({"carId":carId, "carName":carName});
alert("the value stored for carId is: " + $('#myLabelID').data("carId"));
It seems to get to my alert but it’s saying that the value carId is undefined so I don’t know if my first line is right. I know carId has a value.
I want to be able to retrieve this data later on for specific reasons…do I don’t know if I can stash it in this label or not.
use this instead to store data in your dom element.
Any dom element can store data
For retrieval use this