0

I am able to create an array using the following code below. The issue with this is that, what if an individual enters 50 tacos. I am afraid the browser will go through an entire list looking for the rel attribute.

<ul id="taco">
   <li rel="19">other html goes here</li>
   <li rel="50">other html goes here</li>
   <li rel="1535">other html goes here</li>
   <li rel="875">other html goes here</li>
</ul>

$("#taco li").each(function() {
   $tacoOrder.push($(this).attr('rel'));
}); 

So, I was thinking of putting the taco order values in an input box. For example my code looks like this.

<input value="19, 50, 1535, 875">

I want to take the value from this input and create an array. Is this even possible, or is it better to do an each function?

1
  • Yes, it's possible. $('#tacosValue').val().split(',').map(Number) Replace #tacosValue with your selector. Commented Dec 3, 2017 at 4:12

1 Answer 1

1

This can be one solution:

var liObj  = $("#taco li");
//Convert the list to an Array
var arr = jQuery.makeArray(liObj);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.