0

Is it possible to join variables that are cashed selectors?

$('.active').each(function(){
  var $a = $(this);
  var $a_h5 = $a.closest('h5');
  var $a_h4 = $a.closest('h4');
});

Doesn't work:

$('[name=get]').html($($a_h4,$a_h5,$a).map(function() {
  return $(this).html();
}).get().join(', '));

Doesn't work:

$('[name=get]').html($a_h4.add($a_h5).add($a).map(function() {
  return $(this).html();
}).get().join(', '));
2
  • 1
    What are you trying to do exactly here... Commented Jan 25, 2013 at 8:13
  • @elclanrs I'm trying to join content of h4 + content of h5 + content of .active and join all these results if there are more than one .active. Commented Jan 25, 2013 at 8:19

1 Answer 1

1

you could use

$('[name=get]').html($($.merge($a_h4,$a_h5,$a)).map(function() {
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.