I've got a jQuery fucntion that performs a simple Ajax GET in ASP.Net and with the data (Json array) it gets back, populates a web page.
I'm attempting to bind a click event to each div created with the lopp below, but when this is run, all the click events happen on page load simultaneously!
Any ideas?
function grabList() {
    $('#temp').empty();
    $.ajax({
        url: '/Home/GoModel',
        method: 'GET',
        success: function (data) {             
            for (var i = 0; i < data.length; i++) {
                $('#temp').append('<div class="host col-sm-3"> id=' + data[i].name + '>' + data[i].name + '</div>');
                if (data[i].hostConnected === true) {
                    $('#temp').append('<div class="host connected col-sm-3" id=' + data[i].name + '>' + data[i].name + '</div>');
                    continue;
                }
                $('#' + data[i].name).on('click', connect(data[i].name)); // Problem occurs
            }
            $('#container').html($('#temp').html());
        }
    });
}
 
     
     
    