views:

27

answers:

1

1) on main page i have javascript function

function editSuccess(data) { alert("editSuccess called"); }

2) From main page I load some content into div using ajax then i need call javascript function from loaded content but it's don't see editSuccess function

A: 

This should work as long as editSuccess is available in the global scope. Remember that JavaScript has function scope, so if you define editSuccess inside a function, it will only be available within that function. Consider this example:

// javascript
window.onload = function() {
    function editSuccess() {
        alert("Hello");
    }
};

// html
<div onclick='editSuccess()'>..</div>

// or
<script>editSuccess()</script>

will not work since editSuccess does not exist in the global scope.

Anurag
Thank you for fast and helpful answer my function has been located under $(document).ready(function() {and after moving it at the global scope.all became working
SSM