Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

added 315 characters in body
Source Link
Adil
  • 148.3k
  • 25
  • 217
  • 207

You needhave wrong syntax of on as you are not telling what event you want to bind. After binding your required event e.g. click you can use eachmap function to get all the comma separated ids of elements having class star.

Live Demo

$('.star'document).eachon('click', '.star', function(e){ e.stopPropagation();
 ids = $('.star').map(function() {
 var rating = $( return this).attr('id');id;
 }).get().join();
 alert(ratingids);
});

or you canYou need to use map functioneach to getiterate through all the comma separated idselements.

Live Demo

ids = $('.star').mapeach(function(){ 
 returnvar rating = $(this).id;attr('id'); 
}).getalert(rating).join(;
});

You need to use each

$('.star').each(function(){ 
 var rating = $(this).attr('id'); 
 alert(rating);
});

or you can use map function to get all the comma separated ids.

Live Demo

ids = $('.star').map(function(){ 
 return this.id; 
}).get().join();

You have wrong syntax of on as you are not telling what event you want to bind. After binding your required event e.g. click you can use map function to get all the comma separated ids of elements having class star.

Live Demo

$(document).on('click', '.star', function(e){ e.stopPropagation();
 ids = $('.star').map(function() {
  return this.id;
 }).get().join();
 alert(ids);
});

You need to use each to iterate through all elements.

$('.star').each(function(){ 
 var rating = $(this).attr('id'); alert(rating);
});
edited body
Source Link
Adil
  • 148.3k
  • 25
  • 217
  • 207

You need to use each

$('.star').each(function(){ 
 var rating = $(this).attr('id'); 
 alert(rating);
});

or you can use map function to get all the comma separated ids.

Live Demo

ids = $('.star').map(function(){ 
 var rating =return $(this).attr('id');id; alert(rating);
}).get().join();

You need to use each

$('.star').each(function(){ 
 var rating = $(this).attr('id'); 
 alert(rating);
});

or you can use map function to get all the comma separated ids.

ids = $('.star').map(function(){ 
 var rating = $(this).attr('id'); alert(rating);
}).get().join();

You need to use each

$('.star').each(function(){ 
 var rating = $(this).attr('id'); 
 alert(rating);
});

or you can use map function to get all the comma separated ids.

Live Demo

ids = $('.star').map(function(){ 
 return this.id; 
}).get().join();
Source Link
Adil
  • 148.3k
  • 25
  • 217
  • 207

You need to use each

$('.star').each(function(){ 
 var rating = $(this).attr('id'); 
 alert(rating);
});

or you can use map function to get all the comma separated ids.

ids = $('.star').map(function(){ 
 var rating = $(this).attr('id'); 
 alert(rating);
}).get().join();
default

AltStyle によって変換されたページ (->オリジナル) /