Arcath
Arcath

Reputation: 4391

Use the same jquery object in a call

Not sure quite how to describe this but this is what i want to achieve:

$('.class').append($(this).attr("unit"));

but this doesn't append anything, i don't believe that $(this) is the element.

Im not sure how to do this, but if there is a better way like attaching code to an event on a div, but i can't think of any triggers that work on load.

Upvotes: 0

Views: 36

Answers (1)

Nick Craver
Nick Craver

Reputation: 630439

You need to use .each() here to loop though and have this be what you want, like this:

$('.class').each(function() {
  $(this).append($(this).attr("unit"));
});

Inside the .each() callback closure, this refers to the current class="class" element you're on, and runs for each match.

Upvotes: 2

Related Questions