Home > Software design >  How to pass DOM element to JS function - Node cannot be found in the current page error
How to pass DOM element to JS function - Node cannot be found in the current page error

Time:12-03

I'm trying to pass an element to another function and use it in jQuery as a DOM element:

$(document).on('change', selector, function() {
    element = this;
    $.ajax({
        type: 'POST',
        url: url,
        async: false,
        cache: false,
        dataType: 'json',
        data: '',
        success: function (jsonData) {            
            myFunction(element);
        }
    });
});
function myFunction(element) {
    $(element);
}

The element is sent, I can get all the data from it, but it seems that it's not linked to the element in the page:

enter image description here

I can't use $(element).closest('form') for example.


EDIT: I was trying to post a jsfiddle with an example, but I couldn't reproduce it. After testing it harder, I found my mistake

  • Related