質問

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