0

How could I call function in different jQuery wrapper like this:

<?php
        if($trigger != ""){
            ?>
            <script type="text/javascript">
                jQuery(document).ready(function($){
                    var delay = 5000;
                    setTimeout(rmv, delay); // call the function here
                });
            </script>           
            <?php                       
        }
        if($triggered != ""){
            ?>
            <script type="text/javascript">
                jQuery(document).ready(function($){
                    function rmv(){ // function to be called
                        $(".adt_front_wrapper<?php echo $id; ?>").remove();
                    }
                });
            </script>           
            <?php                       
        }
?>

I am trying to call a function which should be separated from the caller like the rmv function in the example code above. How could it be done?

1 Answer 1

3

You would need to put that function into a higher (shared) scope. For this example, you could use the window object itself.

window.rmv = function() {
    $(".adt_front_wrapper<?php echo $id; ?>").remove();
};

In order to make that work, the declaration and definition of rmv needs to happen beforehand of course.

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.