Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing the title of a popover with bootstrap and jquery

here's the html for the link, i.e.:

 <a href="javascript:void(0);" style="font-size: 3em; color: #222" class="popover-test" id="directNavPrev" data-title="Previous Result Row" data-content="Previous Result Row">
&laquo;</a>

yes, i'm calling .popover() to initialize and the popover works just fine. i can get the content to update with no problem. just not the title. i've tried "prev.data('title','new title')" and even tried to re-init "prev.popover({title:'new title'});" with no dice... thanks.

 function SetDirectNavigationPlaceholder() {
    //debugger;
    var item = $("#movementType :selected").val();
    var direct = $('#directNavigation');
    var prev = $('#directNavPrev');
    var next = $('#directNavNext');
    switch (item) {
        case "result":
            $('#bookTypeSection').addClass('hide');
            direct.val('Result Row from 1 - 150');
            prev.attr('data-title', "Previous Result Row");
            next.attr('data-title', "Next Result Row");
            prev.attr('data-content', "Check it! this will contain the information for the previous result<table><tr><td>blah</td><td>blah</td></tr><tr><td>blah</td><td>blah</td></tr><tr><td>blah</td><td>blah</td></tr><tr><td>blah</td><td>blah</td></tr></table>");
            next.attr('data-content', "Check it! this will contain the information for the next result<table><tr><td>blah</td><td>blah</td></tr></table>");
            break;
        case "instrument":
            $('#bookTypeSection').addClass('hide');
            direct.val('Instrument #');
            prev.attr('data-title', "Previous Instrument #");
            next.attr('data-title', "Next Instrument #");
            prev.attr('data-content', "Check it! this will contain the information for the previous <b>instrument</b><table><tr><td>blah</td><td>blah</td></tr></table>");
            next.attr('data-content', "Check it! this will contain the information for the next <b>instrument</b><table><tr><td>blah</td><td>blah</td></tr></table>");
            break;
        case "bookpage":
            $('#bookTypeSection').removeClass('hide');
            direct.val('Book/Page');
            prev.attr('data-title', "Previous Book/Page");
            next.attr('data-title', "Next Book/Page");
            prev.attr('data-content', "Check it! this will contain the information for the previous <b>book/page</b><table><tr><td>blah</td><td>blah</td></tr></table>");
            next.attr('data-content', "Check it! this will contain the information for the next <b>book/page</b><table><tr><td>blah</td><td>blah</td></tr></table>");
            break;
    }
    direct.css('color', '#aaa').not('#directNavigationHeader');
}
like image 305
chaz stone Avatar asked Jul 25 '12 18:07

chaz stone


People also ask

How do I customize bootstrap popover?

To create a popover, you need to add the data-bs-toggle="popover" attribute to an element. Whereas, popover's title and its content that would display upon trigger or activation can be specified using the title and data-bs-content attribute respectively. Here is the standard markup for adding a popover to a button.

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.

How do you use bootstrap popovers?

To create a popover, add the data-toggle="popover" attribute to an element. Note: Popovers must be initialized with jQuery: select the specified element and call the popover() method.


1 Answers

The easiest way to do it is this one :

     var newTitle = "Here's my new title";
     $('#MyExample').attr('data-original-title', newTitle);

Hope it helped !

like image 116
Yann Chabot Avatar answered Oct 01 '22 22:10

Yann Chabot