4

this is what I've got:

<ul class="sortable">
<li data-order=""><input class="cant-see-me" value="3" /></li>
<li data-order=""><input class="cant-see-me" value="1" /></li>
<li data-order=""><input class="cant-see-me" value="2" /></li>
</ul>

I need this:

<ul class="sortable">
<li data-order="3"><input class="cant-see-me" value="3" /></li>
<li data-order="1"><input class="cant-see-me" value="1" /></li>
<li data-order="2"><input class="cant-see-me" value="2" /></li>
</ul>

I'd need to populate data-order values with ones found in input field. I've tried with each function, but all I've got was value from first input field "3" to be inserted into data-order.

this is what I've tried + many variations of it

$.each($('.sortable li'), function (index, value) { 
/*  $('.sortable li').each(function() {  this one had the same result*/

  var bla = $('.cant-see-me').val();
  $(this).attr('data-order', (bla));

});

Thank you

0

1 Answer 1

2

The way you're trying to do it is getting every element with the 'cant-see-me' class. This would return back an array of 3 input elements according to the HTML. You need to get the value of the 'cant-see-me' class belonging to each individual <li> element:

var bla = $($(this).find('.cant-see-me')).val();
$(this).attr('data-order', bla);
Sign up to request clarification or add additional context in comments.

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.