In this tutorial, I will describe how to use bootstrap popover for custom HTML control, normally we used popover to display tooltip information on help, but sometimes we need HTML control or HTML form in the popover. This tutorial helps you to create HTML control on popover.
The bootstrap popover is used to show information or HTML element. Bootstrap is a very popular CSS framework to create elegant UI within minutes. This Bootstrap tutorial help to create a beautiful popover using static information or HTML content.
You can use popover using data attribute or JavaScript. There are a lot of callback method and events available for bootstrap popover.
Also Checkout other Popup Box tutorial,
You can define popover on anchor/button element using data-toggle = "popover"
attribute. The title of the anchor/button will be the text of a popover which will show. The default position of popover is top by the plugin.
<button class="btn btn-primary" title="Popover title" type="button" data-toggle="popover" data-placement="top" data-content="Default popover">Popover on top</button>
data-toggle :
Use to activate the popover on the element.data-content :
Use to display content inside the popover’s body.You can also initialize popover on the HTML element using the jquery selector. We can use HTML element Id/Class as a jQuery selector and call popover() method on it. The following code will enable popovers on all HTML elements which has data-toggle
attribute.
<script> $(document).ready(function(){ $('[data-toggle="popover"]').popover(); }); </script>
Step 1: Include all necessary library into head section of index.php
file.
<link rel="stylesheet" href="/bootstrap/3.2.0/css/bootstrap.min.css"> <link rel="stylesheet" href="/bootstrap/3.2.0/css/bootstrap-theme.min.css"> <script src="/jquery/1.11.1/jquery.min.js"></script> <script src="/bootstrap/3.2.0/js/bootstrap.min.js"></script>
Step 2: We need to define HTML layout.
<div id="popover1" class="col-sm-12 col-xs-12 col-md-9"><a class="btn btn-primary change-trigger" title="" data-original-title="popover Test">Popover Example</a> <div id="select-div" class="hide"> <div class="col-sm-2 " style="width: 250px;"><select class="form-control"> <option>Test</option> <option>Test1</option> </select></div> <div class="clearfix col-sm-10" style="margin: 8px 0;"><button class="btn btn-default btn-go" type="button">Go!</button> <button class="btn btn-default btn-cancel-option" type="button">Cancel</button></div> </div> </div>
Above code create a link button which will use to generate a popover on click. We have HTML select control with hide properties.
Step 3: Now we will call the bootstrap popover method.
$('.change-trigger').popover({ placement : 'Right', title : 'Change', trigger : 'click', html : true, content : function(){ var content = ''; content = $('#select-div').html(); return content; } }).on('shown.bs.popover', function(){ }); $(document).delegate('.btn-go','click', function(e){ e.preventDefault(); alert('Go Click'); }); $(document).delegate('.btn-cancel-option', 'click', function(e){ e.preventDefault(); var element = $(this).parents('.popover'); if(element.size()){ $(element).removeClass('in').addClass('out'); } });
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More
View Comments
Hi Parvez
I am trying to place a drop down in body of popover and depending on selected value in dropdown I want to show data related to that selected option in the same body of the popover how can I achieve this........
You can call ajax request to fill data in your body based on dropdown id.
error?