I am using the following code:
$('select.update-grid')
.each(function () {
var id = this.id.replace('modal', '');
var sel = this.find("option:selected").text();
var val = this.val()
$('#input' + id)
.val(val)
.attr('title', sel);
})
It works by finding all the selects with a class of update-grid. When I step through this code I get an error on the line starting with “var sel”.
SCRIPT438: Object doesn't support property or method 'find'
Does anyone know what can be wrong with my code?
when you are running .each() then this refers to the current select.update-grid DOM element, not a jquery Reference of it:
is what you are looking for I think.