Вопрос

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