简体   繁体   中英

how to call a function after appending it in jquery

i am appending a div using ajax and alnog with that div a function (it's a time ago function) the function needs to be called as soon as the div is appended I've tried all possible solutions but none works

my function (located in processor.php page)

 <script>
 $(document).ready(function () {
    $('.post_the_stat').click(function(event) {event.preventDefault();

    $.ajax({
        type: "POST",
        url: "addition_life_text.php",
        data: 'final_text='+ fin_text +'&priv='+ priv + '&post_time='+post_time ,
        success: function(data) {
                 $(".main_container").prepend(data);
                                }

          })
    })
 })
 </script> 

the function

<script>
function ago()
{
  //codeblock
} 
</script>

my question:how do i call the function ago as soon as the ajax was success is appended.ive tried window.onLoad etc...

<script>
 $(document).ready(function () {
    $('.post_the_stat').click(function(event) {event.preventDefault();
    $.ajax({
        type: "POST",
        url: "addition_life_text.php",
        data: 'final_text='+ fin_text +'&priv='+ priv + '&post_time='+post_time ,
        success: function(data) {
            $(".main_container").prepend(data);
            ago();
        }

     })
    })
 })
 </script> 

Please try above. Hopefully this will work

Try this

 success: function(data) {
             $(".main_container").prepend(data).go();
                            }

      })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM