Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the bootstrap popover position for a particular element

I am using the bootstrap popover on a table of data as you will see from my jsFiddle below each cell creates a popover when clicked on.

I am trying to adjust the position or 'placement' of the popover for the last td in a row, the idea is when the last cell is clicked the popover will be positioned to the left rather than the top.

You will see if you scroll to the end of the table click on the last cell i have implemented the selection but not the positioning.

Any ideas on how to achieve this?

http://jsfiddle.net/N8NNC/1/

Heres by javascript for the popovers:

$(".metapop").popover({ 

    html: true,
    trigger: 'manual',
    placement: 'top',
    title: "You clicked on this cell:",
    content: 'hello this is a popover'

}).click(function(e) {

        $('.popover').hide();
        $(this).popover('show');
        if($(this).parent().is('td:last-child'))
            {
                alert($(this))
            }
    });
like image 424
Tom Avatar asked Apr 09 '13 12:04

Tom


People also ask

How do you change the placement on a popover?

Tip: You can also use the data-placement attribute with a value of "auto", which will let the browser decide the position of the popover. For example, if the value is "auto left", the popover will display on the left side when possible, otherwise on the right.

How do I change the popover position in bootstrap?

Positioning with Margins So to move the popover more to the left, we can add a negative margin-left, or a positive one to move it further to the right. Likewise, we can move the popover more up by adding a negative margin-top, and down by using a positive value.

What appends the popover to specific elements?

Popover Options. Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-placement="". Appends the popover to a specific element.

Which attribute is used to set the position of popover?

Positioning popovers: The data-placement attribute is used to set the positioning of popover elements. The position of popover element can be set to top, bottom, left or right side of the element.


1 Answers

You could assign a function to the 'placement' option like this..

$(".metapop").popover({ 

    html: true,
    trigger: 'manual',
    placement: function(pop,ele){
        if($(ele).parent().is('td:last-child')){
        return 'left'
        }else{
        return 'top'
        }
    },
    title: "You clicked on this cell:",
    content: 'hello this is a popover'

})
like image 92
Zim Avatar answered Oct 23 '22 15:10

Zim