Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a null jQuery data item?

$("selector").data("name", null);
console.log($("selector").data("name"));

This prints undefined.

Is there anyway to instantiate a null item in the jQuery data object of an element, not an undefined one?

like image 205
Mox Avatar asked Nov 26 '25 12:11

Mox


1 Answers

Yes and Your code works fine, You should check if your $("selector") exists

like image 70
Sebastian Krysiak Avatar answered Nov 28 '25 02:11

Sebastian Krysiak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!