javascript - Bootstrap tooltip only on first image - Stack Overflow

How can I make to show up bootstrap tooltip to every image ? Why is it showing up only on first image l

How can I make to show up bootstrap tooltip to every image ? Why is it showing up only on first image like this:

This is my code:

       <ul class="row list-unstyled">
   @foreach($facilities as $facility)

                <div class='col-md-3 text-center'>
                <a data-toggle="lightbox" href="/{{$facility->image}}">

                <img class="thumbGlassFac" src=".png">

                    <img id="images" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom"
                     class="thumbBorderFac" style="height: 180px; width: 180px; line-height: 80px" src="/{{$facility->image}}"/></a>
                    <hr>
            </div> <!-- col-6 / end -->

   @endforeach  
   </ul>

When I hover my mouse to other images the tooltip doesn't showing up.

$('#images').tooltip();

How can I make to show up bootstrap tooltip to every image ? Why is it showing up only on first image like this:

This is my code:

       <ul class="row list-unstyled">
   @foreach($facilities as $facility)

                <div class='col-md-3 text-center'>
                <a data-toggle="lightbox" href="/{{$facility->image}}">

                <img class="thumbGlassFac" src="http://m-w.lt/prekes/white-magnifying-glass-hi.png">

                    <img id="images" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom"
                     class="thumbBorderFac" style="height: 180px; width: 180px; line-height: 80px" src="/{{$facility->image}}"/></a>
                    <hr>
            </div> <!-- col-6 / end -->

   @endforeach  
   </ul>

When I hover my mouse to other images the tooltip doesn't showing up.

$('#images').tooltip();
Share Improve this question asked Dec 13, 2015 at 21:31 frenchbaguettefrenchbaguette 1,3396 gold badges22 silver badges43 bronze badges 2
  • Most likely (but not confirmed) because you should only have one id on the page, but you have the same id for all of your images. Does your $facility have some form of unique id that can be added to id? eg <img id="images-{{$facility->id}}" ...` – fdomn-m Commented Dec 13, 2015 at 21:34
  • $('#images') will only give you the first element with matching id. Change to use the class. – fdomn-m Commented Dec 13, 2015 at 21:36
Add a ment  | 

3 Answers 3

Reset to default 3

Make sure that your element ids are unique.

<img id="images" />

will generate multiple elements with the same id in the loop, which is invalid. Try to append the loop index to the id and generate unique ids for your elements. So the resulting HTML will be something like

<img id="images1" />
<img id="images2" />
<img id="images3" />

Change

$('#images').tooltip(); // id selector will return only 1 DOM element

to

$(".thumbBorderFac").tooltip(); // class selector returns multiple elements with the same class name

Add an id to the parent element of the images and restrict your selector to run under that element only.

<ul class="row list-unstyled" id="imageContainer">

and change your code to

$("#imageContainer").find(".thumbBorderFac").tooltip();

ID Selector (“#id”)

Class Selector (“.class”)

Because you have the same id for all images. Change the images id to a class.

what about using "class" instead of "id"? I had a problem similar and solved by using a class as selector.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745325808a4622651.html

相关推荐

  • javascript - Bootstrap tooltip only on first image - Stack Overflow

    How can I make to show up bootstrap tooltip to every image ? Why is it showing up only on first image l

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信