Get date-img value

Asked

Viewed 143 times

3

I have the following problem:

I am getting the value of data-img when I do Hover in class . gettoll, but I need to replace this value here content: "<img src='IMAGEM AQUI'>", when hovering over each of the items, the problem is that they are all displaying the same image.

OBS: as li's are within a while() using a Carousel I I simplified to put here...

Would anyone have any idea how to solve the problem ?

JS

<script>
$(document).ready(function() {

$(".gettool").hover(function(){
    var imagetooltip = $(this).data("img");

    console.log(imagetooltip);
});

    $(".tooltip").tooltipster({
        animation: "grow",
        contentAsHTML: true,

        content: "<img src='IMAGEM AQUI'>",
        multiple: true
    });
});
</script>

HTML

<ul>
<li><a href="#" class="gettool tooltip" data-img="images/qualquer.jpg"><img src="images/01.jpg"></a></li>
<li><a href="#" class="gettool tooltip" data-img="images/qualquer.jpg"><img src="images/01.jpg"></a></li>
<li><a href="#" class="gettool tooltip"data-img="images/qualquer.jpg"><img src="images/01.jpg"></a></li>
</ul>

4 answers

1


Take a look here at us methods of this plugin.

What he’s missing is:

    var novaImagen = '<img src="' + imagetooltip + '" />'
    $(this).tooltipster('content', novaImagen)
    $(this).tooltipster('show');

Example without formatting => http://jsfiddle.net/tVsXY/

  • Perfect! thank you so much solved exactly the problem.

1

Use the selector switch $(this).attr("data-img") instead of $(this).data("img");

  • Leandro, I have tested this possibility before and the problem remains the same.

1

Call the tooltip inside where you call the function of Hover and in place of the 'IMAGE HERE put the variable that has the value of the data img. That should solve.

  • almost there, but now when I step the mouse it displays 11 links of the same image and always the last is the same, ie it is opening all underneath

  • Call the tooltip only with the content parameter to see. It makes no sense to bring 11 links.

  • I am only trying with the content parameter opens only once but the console still shows several repeated links content: "imagetooltip" <- does not print the url

  • Are you concatenating? It should stay: content: "<img src='+ imagetooltip +'>";

  • I had already tried to concatenate also and persists the same result

1

$(".gettool").hover(function(){
    var imagetooltip = $(this).attr("data-img");
    $(this).find('img').attr('src', imagetooltip);
});

I’m doing like this now:

$(document).ready(function(){
    $('.tooltip').hover(function(){
        var imagetooltip = $(this).attr('data-img');

        $('.tooltip').tooltipster({
            content: $(this).find('img').attr('src', imagetooltip),
            multiple: true
        });
    });
});

but the tooltip always brings the image of the previous link in relation to what I did . Hover()

  • For a more complete answer explain your solution. This will help people who see this question in the future to understand the various solutions proposed and the difference or similarity between them. To better understand how to answer give a read on Centra de Ajuda

  • We got closer, but I can’t print the image inside the tooltip yet, but outside the tooltip

  • $(document).ready(function(){&#xA; $('.gettool').hover(function(){&#xA; var imagetooltip = $(this).attr('data-img');&#xA; &#xA; //$(this).find('img').attr('src', imagetooltip);&#xA; &#xA; $('.tooltip').tooltipster({&#xA; content: '<img src="+imagetooltip+">',&#xA; multiple: true&#xA; });&#xA; });&#xA;});&#xA;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.