Bfca16459c82a7836c3d5c8d79f0b640

I get a change event within the select and now I need the id of the corresponding <select>. I was successfull with filter.get(0).id, but I believe there is a more jQuery way to do this.

$('.answer_filter').change(function() {
  var filter = jQuery(this);
  var select = jQuery('#' + filter.get(0).id); // @TODO find a more appropriate solution
  ...
});

Refactorings

No refactoring yet !

23132e1aa8457e11b243a43b578d51dc

Simo Niemelä

January 27, 2009, January 27, 2009 18:05, permalink

2 ratings. Login to rate!
$('.answer_filter').change(function() {
  var filter = $(this);
  var select = $('#' + filter.attr('id'));
});
Aacfa176a8d73ca75b90b6375151765a

paul.wilkins.myopenid.com

January 27, 2009, January 27, 2009 18:59, permalink

1 rating. Login to rate!

The filter variable is the same element as the this keyword. By getting the first match with get(0) that's still referring to the same element. So, the select variable can be assigned to the this keyword, which achieves the same result.

$('.answer_filter').change(function () {
  var select = $(this);
  ...
});
D41d8cd98f00b204e9800998ecf8427e

Vasco Costa

October 8, 2010, October 08, 2010 10:18, permalink

No rating. Login to rate!
$('.answer_filter').change(function() {
  var select = jQuery(this).attr('id');
});

Your refactoring





Format Copy from initial code

or Cancel