Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble setting data with $.data()

Tags:

jquery

I can't seem to get this to store. I now that the id and name are definitely valid as I alerted them out right before this code was called:

$('#carText').data("carId", carId);
$('#carText').data("carName", carName);

alert("value stored for carId: " + $("#carText").data("carId").carId);

I get undefined when I try to alert out the value that I supposedly stored.

like image 660
PositiveGuy Avatar asked Mar 19 '26 01:03

PositiveGuy


1 Answers

don't need the .cardId at the end

alert("value stored for carId: " + $("#carText").data("carId"));
like image 169
Kris Ivanov Avatar answered Mar 20 '26 18:03

Kris Ivanov