I'll try to be more specific. I have a <ul>
list that is populated via jQuery:
var $imovel = $("#lista-resultados-pesquisa");
$.ajax({
type: 'GET',
url: 'imovel.json',
success: function(data) {
$.each(data.imovel,function(i, imovel){
$imovel.append('<li value="'+ imovel.preco +'">Meu conteudo</li>');
})
}
});
Because the items in my list are not in the html, I can not manipulate them ... For example, I need to sort my list according to the value
attribute of <li>
tags, and I also need to have one loadMore
button to limit the amount of elements that appear on the screen. I already have this, the problem is that I can not manipulate the items in my " <li>
" list that are being inserted dynamically, so to speak, from my local json file.
I will show the functions for sorting and loadMore that I have with me.
//LOADMORE
var size_li = $("#lista-resultados-pesquisa .intens-pesquisa").size();
var x=3;
$("#lista-resultados-pesquisa .intens-pesquisa:lt("+x+")").show();
$("#loadMore").click(function () {
x= (x+3 <= size_li) ? x+3 : size_li;
$("#lista-resultados-pesquisa .intens-pesquisa:lt("+x+")").show();
if(x == size_li){
$("#loadMore").hide();
}
});
//ORDENA
$('.ordena-menor').click(function() {
$("#lista-resultados-pesquisa .itens-pesquisa").sort(numOrdDesc).appendTo('#lista-resultados-pesquisa');
});
$('.ordena-maior').click(function() {
$("#lista-resultados-pesquisa .itens-pesquisa").sort(numOrdCres).appendTo('#lista-resultados-pesquisa');
});
function numOrdDesc(a, b) {
return ($(b).val()) < ($(a).val()) ? 1 : -1;
}
function numOrdCres(a, b) {
return ($(b).val()) > ($(a).val()) ? 1 : -1;
}
Thanks Gurizada, a big hug and a great weekend everyone!