0

I have an input boxes

<ul>
  <li>
    <label><input type="text" title="1"></label>
 </li>
 <li>
    <label><input type="text" title="2"></label></li>
</ul>

Jquery

 $('.editdets').click(function(e){e.preventDefault();
    var inp =$('ul>li>label>input:title').toArray()
    alert(inp);
 });

I want to get all title(s) from input fields and store them into array.

I can't use attr().toArray as it then says to array is not a function.

2 Answers 2

1

You can use $.map(), return HTMLElement.title

 var inp = $.map($("ul>li>label>input"), function(input) {
   return input.title
 });
 console.log(inp);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
  <li>
    <label>
      <input type="text" title="1">
    </label>
  </li>
  <li>
    <label>
      <input type="text" title="2">
    </label>
  </li>
</ul>

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

var itemlist = [];
$("input").each(function (a, b) {                
     itemlist.push($(b).attr("title"));
     console.log(itemlist);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.