Pergunta

Eu estou usando jQuery e jQuery UI.

Usando a função getJSON, estamos criando elementos da lista e anexando-os a um elemento OL. Aqui está o código:

$.getJSON("http://localhost/b/t.php", function(data){

        $.each(data, function(i, thet){
            //alert(thet.fname)
            var t = '<li class="name" id="p' + thet.pid + '">' + thet.pid + ' ' + thet.fname + ' ' + thet.lname + '</li>';

            $(t).appendTo("#" + thet.tour + 'list');

        });
    });

Eu estou tentando selecionar os elementos da lista usando jQuery. Se eu colocar manualmente uma lista na página HTML, ele vai trabalhar. No entanto, programaticamente anexar os itens da lista a um OL, não permitir que ele escolha -. Pelo menos desde que eu tentei

$('li:last-child').css({color: 'red', backgroundColor: 'black'});

Eu tentei usar ID de e muitas outras vários seletores, sem sucesso.

Todas as idéias?

Foi útil?

Solução

Quando você está tentando executar esse comando que cores os itens da lista? Eu acredito que você terá que colocar no final da função de retorno de getJSON da seguinte forma:

$.getJSON("http://localhost/b/t.php", function(data){
    $.each(data, function(i, thet){
        //alert(thet.fname)
        var t = '<li class="name" id="p' + thet.pid + '">' + thet.pid + ' ' + thet.fname + ' ' + thet.lname + '</li>';

        $(t).appendTo("#" + thet.tour + 'list');
    });
    $('li:last-child').css({color:'red',backgroundColor:'black'});
});
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top