$('.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 !
Simo Niemelä
January 27, 2009, January 27, 2009 18:05, permalink
$('.answer_filter').change(function() {
var filter = $(this);
var select = $('#' + filter.attr('id'));
});
paul.wilkins.myopenid.com
January 27, 2009, January 27, 2009 18:59, permalink
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);
...
});
Vasco Costa
October 8, 2010, October 08, 2010 10:18, permalink
$('.answer_filter').change(function() {
var select = jQuery(this).attr('id');
});
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.