i have a few li's:
<ul>
<li class="one">
<input type="text" class="form_input" placeholder="Type something...">
</li>
<li class="two">
<input type="text" class="form_input" placeholder="Type something else...">
</li>
</ul>
i am trying to create a array similar to:
[
0[
'placeholder' : 'Type something...'
]
1[
'placeholder' : 'Type something else...'
]
]
i use a method like this
var lineText = function(elements) {
var myData = new Array();
elements.each(function(index, data) {
var li = $(this);
myData["placeholder"] = li.find('.form_input').attr("placeholder");
console.log(data); returns the li objects
});
console.log(myData);
};
from this i get [placeholder: "Type something..."]
, basically one item in my array, instead of 2
i can't use push
like this:
myData["placeholder"].push(li.find('.form_input').attr("placeholder")); //Cannot call method 'push' of undefined
or add another dimension to the array
myData[index]["placeholder"] = li.find('.form_input').attr("placeholder"); //Cannot set property 'placeholder' of undefined
any ideas? thanks
data
in this case – Patrioticcow Nov 8 '12 at 21:44