2

I'm reloading the contents of "#some-div" using ".load()" after processing some form data. This works just fine and "#some-div" is refreshed with the expected updated content. The problem is that none of my other assigned jQuery functions (e.g. ".some-trigger" below) will work for elements within "#some-div" after it has been refreshed. Any insight is much appreciated. Here's a simplified representation of my code.

<div id="some-div">
    <a class="some-trigger" href="#">I Won't Work Anymore After I've Been Refreshed</a>
</div>

<script> 
    $('.ajax-form').ajaxForm(function() {  
        $("#some-div").load(location.href+" #some-div>*","");
    });

    $('.some-trigger').someFunction();
</script>

1 Answer 1

1

you should delegate the click event for dynamically loaded elements, try the following:

$("#some-div").on('click', '.some-trigger', function() {
   // do something here
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.