Skip to content Skip to sidebar Skip to footer

Losing Jquery Delegated Event Handler

I've to do some stuff when a changed occure in a TextBox in a GridView.. So I've: $(function () { $('.mGrid').on('change', 'input[id*='txtValore']', function () { alert

Solution 1:

If your button "that switches panels" replaces the current grid, you need to delegate it back to a higher non-changing ancestor:

e.g. document

$(function () {
    $(document).on('change', '.mGrid input[id*="txtValore"]', function () {
        alert('CHANGE!!');
        (...)
    });
});

This now reads as... if any change event bubbles up to document, run the '.mGrid input[id*="txtValore"]' selector to find the element that caused it, then fire the function against that element.

note:document is just your fallback default if nothing else is closer that does not change. Do not use 'body' as styling can cause it to not receive bubbled mouse events.

Post a Comment for "Losing Jquery Delegated Event Handler"