JQUERY object with dynamic string

0

I have a for () that adds some elements in the div # chat_box according to the JSON returned in an AJAX. Only I'd like to see how many elements with the same data-identity returned in JSON exist. So I did like this:

// AJAX -> SUCCESS: FUNCTION(data){
// data É RETORNADO EM JSON
for( var i = 0; i < data.msgs; i++){
										
							if($('.msg[data-identity=' + data[i]['identity'] + ']').lenght){
											$('#chat_box').append('<div data-identity="' + data[i]['identity'] + '" class="msg user_' + data[i]['time'] + '"><span>'+ data[i]['nick'] + ': </span>' + data[i]['contente'] +'</div)');	
							}		
}
//}

It just does not work and I think it's because of this line:

if($('.msg[data-identity=' + data[i]['identity'] + ']').lenght){

But I do not know how to put a dynamic parameter (date [i] ['identity']) in the jquery object ($ ('. msg ...'))), it does not work the way I put it. p>

Can anyone help?

    
asked by anonymous 02.07.2018 / 23:58

0 answers