Reputation: 47595
I have:
<td data-X="1,2">
and when I do:
var Y = $('td').data('X');
Z=Y.split();
it works.
But if I have:
<td data-X="1">
then it doesn't work. At least I think that's what's happening. I'm getting "Y.split is not a function", but only sometimes.
Upvotes: 0
Views: 143
Reputation: 318488
.data()
is smart. It tries to use a more appropriate type than string
for the value - in your case, it's number
.
From the docs:
Every attempt is made to convert the string to a JavaScript value (this includes booleans, numbers, objects, arrays, and null) otherwise it is left as a string. To retrieve the value's attribute as a string without any attempt to convert it, use the attr() method.
Upvotes: 1
Reputation: 3989
I wonder if it's being interpreted as an integer instead of a string. Try Z = Y.toString( ).split( )
Upvotes: 4