50
rated 0 times
[
51]
[
1]
/ answers: 1 / hits: 17944
/ 10 Years ago, sat, march 1, 2014, 12:00:00
I have this HTML:
<section id=SSID data-texts='Text1', 'Text2', 'Text3'></section>
I want to create an Array variable in jQuery and my jQuery code is:
$(document).ready(function() {
var Selection = $(#SSID).data(texts);
var Texts = [ Selection ];
console.log(Texts.length);
});
For my example, the result I expect is:
Texts[0] = 'Text1'
Texts[1] = 'Text2'
Texts[2] = 'Text3'
...and that the length of the array Texts
is 3.
However, what I am seeing is that the length of Texts
is 1 and that the entire string is being loaded into Texts[0]
:
Texts[0] = 'Text1', 'Text2', 'Text3'
I think my problem is being caused by the (quotation mark) characters. How can overcome this problem and achieve my objective?
More From » jquery