0

I want to select all the elements with the class "play" and add them into array "esArreglo".

html file:

<td id="b1" class></td>
<td id="b2" class></td>
<td id="b3" class="play"></td>
<td id="b4" class="play"></td>

code:

$('td.play').each(function() {
    notas.push(this.id)};

var esArreglo = notas.join(',');

How can I fix this? Thanks.

1
  • 2
    What is the problem? You code looks fine except for a stray missing ) at the end before your var esArreglo statement, ie }); right after the notas.push.... And move the ; to after the .push() part. Commented Aug 17, 2012 at 15:02

2 Answers 2

1

You could use jQuery.map

var esArreglo = $('td.play').map(function() {
  return this.id;
}).get().join(',');
Sign up to request clarification or add additional context in comments.

1 Comment

$.fn.map(), which you're using in your answer, behaves a little differently than $.map(). It returns a jQuery object, not an array, so you have to call get() before join() for your code to work.
0

May coz be you are missing the ); in .each

$('td.play').each(function() {
    notas.push(this.id)
});

var esArreglo = notas.join(',');

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.