문제

I am new to jQuery and hope someone here can help me with this:

Basically what I am trying to do is the following:

  1. Check for all elements with the class "limit" and get their maxlength.
  2. Find an element with the class "count" in the same row.
  3. Add the found maxlength to the count element's text.

I am using the following but this displays the last maxlength for all the elements in question. My guess is that my last element is perhaps overwriting the others. Can someone tell me what I have to change here ?

var limit = '';
$('.limit').each(function() {
    limit = $(this).attr('maxlength');
    $(this).closest('tr').find($('.count').text(limit));
});

Many thanks in advance, Mike.

도움이 되었습니까?

해결책

Try to use:

$(this).closest('tr').find('.count').text(limit);

You don't need to convert .count to jQuery object inside .find() method. You also need to put .text() outside of .find()

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top