# Trigger a jquery function on post load

**URL:** <https://meta.discourse.org/t/trigger-a-jquery-function-on-post-load/85003>\
**Category:** Development\
**Created:** [April 10, 2018, 6:23pm UTC](https://meta.discourse.org/t/trigger-a-jquery-function-on-post-load/85003 "2018-04-10T18:23:59Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Olivier\_Lambert](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/olivier_lambert/32/74807_2.png) [@Olivier\_Lambert](https://meta.discourse.org/u/Olivier_Lambert)\
**Post date:** [April 11, 2018, 5:10pm UTC](https://meta.discourse.org/t/trigger-a-jquery-function-on-post-load/85003/6 "2018-04-11T17:10:52Z")

</div>

I don’t want to display the user’s trust level, I did a custom leveling system that’s partly based on action made on both wordpress AND discourse.

Here’s the best workaround I’ve found so far:

```plaintext
// I fetch my JS object containing all my members with user levels, calculated server side.
$.get('https://www.latranchee.com/php/users/gamification.php', function( data ) {
    users = JSON.parse(data);
});

// The function that will add users level next to their name
function add_levels(){
    $('.topic-avatar img.avatar:not(.lvl)').each(function(){
        var username = $(this).attr("title");
        if(window.users[username]){
            $(this).after("<span class='user_level_img'>"+window.users[username]+"</span>")
        }
        $(this).addClass("lvl");
    });
}

// A timer that triggers the check Avatar function
window.setInterval(function(){
  checkForAvatar();
}, 1000);

// A function that check if there's an image on the page without it's level being displayed.
function checkForAvatar(){
   if ( $('.topic-avatar img.avatar:not(.lvl)').length ){
       add_levels();
    }
}

```

Far from optimal, but I guess it will have to do.

---

_[View the full topic](https://meta.discourse.org/t/trigger-a-jquery-function-on-post-load/85003)._
