1

Tenho um pequeno slide show, mas na hora de por a legenda ele não retorna nada(tem o atributo alt nas imagens que eu quero usar)

Abaixo tenho o script que eu estou utilizando:

$(document).ready(function () {
    $('.abre-fecha').hide();
    $('.foto').each(function (i) {
        $(this).replaceWith('<div id="fundoNum"><div id="numeroSlide"><span title="' + $(this).attr('alt') + '">' + (i + 1) + '</span></div></div>');
        $('#galeria').css('textAlign', 'center');
    });
    $('<div id="tela" ><img src="1.jpg" alt="Descrição da imagem" /></div>')
        .insertBefore('#galeria')
    $('#galeria a').click(function (event) {
        event.preventDefault();
        if (!$('#tela img').is(':animated')) {
            $('.legenda').remove();
            var legenda = $(this).children('span').attr('title')
            $('#galeria a').removeClass("corrente");
            $(this).addClass("corrente");
            $('#tela img').attr('src', $(this).text() + '.jpg')
                .css('opacity', '0.3').animate({
                opacity: 1
            }, 1500,

            function () {
                $('#tela').append('<p class="legenda">' + legenda + '</p>');
                $('.legenda').css('opacity', 0.6)
            });
        }
    });
});

e meu HTML está assim

<div id="galeria">
     <ul>
        <a href="1.jpg"><li><img src="1.jpg" width="500px" height="300px" class="foto" alt="descrição 1"></li></a>
        <a href="2.jpg"><li><img src="2.jpg" width="500px" height="300px" class="foto" alt="descrição 2"></li></a>
        <a href="3.jpg"><li><img src="3.jpg" width="500px" height="300px" class="foto" alt="descrição 3"></li></a>
     </ul>
 </div>
0

1 Resposta 1

3

Usa o .find() em vêz do .children(). Na documentaçao do jQuery refere

.children() only travels a single level down the DOM tree while

ou seja, o .children() desce só um nível no DOM, enquanto que o .find() não, e o qu eprecisas é this > li > div > div > span.

Usa portanto:

var legenda = $(this).find('span').attr('title')
1
  • Muito obrigado Sergio
    – Naldson
    19/06/2015 às 14:13

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .