Problem with fetch an jjquery chaining

Hi I have this problem I have a code:

        contributorsArr.forEach(function(obj1) {
            users.forEach(function(obj) {
                if ( === {
                    Object.assign(obj, obj1)
            return users;
        $.each(users,function (index,user) {
            var that = this;
            $(document).on('click','#userPanel',function (user) {
                    <div id="userPanel" class="panel panel-default">
                      <div class="panel-heading">
                        <h3 class="panel-title">${ ? : user.login}</h3>
                      <div class="panel-body">
                        <div class="row">
                            <div class="col-md-3 ">
                                <img class="thumbnail avatar" src="${user.avatar_url}" alt="avatar">
                                <a target="_blank" class="btn btn-primary btn-block" href="${user.html_url}">View Profile on GitHub</a>
                            <div class="col-md-9">
                            <span class="label label-default">Public Repos: ${user.public_repos} </span>
                            <span class="label label-primary">Public Gists: ${user.public_gists}</span>
                            <span class="label label-success">Contributions: ${user.contributions}</span>
                            <span class="label label-info">Followers: ${user.followers}</span>


Problem is that this line $(document).on('click','#userPanel',function(user){console.log($(this)}); is giveing me error: Uncaught TypeError: Cannot read property ‘name’ of undefined;

Im struggle with this for a days and just dont know how to handle it

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

1 Like

Thank you , ill try better next time

you need to bind the this to the $.each … as when you click the userpanel the this is bound to that … so you need to create a var eg var that = this and then use that instead o this lol … look at my simple repel on the index.js page it should make it more clear

1 Like

Hey John thank you for your help!