Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add vertical menu items to Bootstrap popover?

I'm using Bootstrap v3.3.5 in my website. I want to open-up a popover which contains three menu items separated by horizontal lines.

Menu items should be vertical and should be as follows :

  • Edit Event
  • Invite Members
  • Delete Event

Each of the menu items should be hyperlink to open-up some new modal dialog or something like that. For it I tried below code but it didn't work out for me.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <a href="#" data-toggle="popover">Toggle popover</a>
</div>

<script>
$(document).ready(function(){
    $('[data-toggle="popover"]').popover();   
});
</script>
like image 999
PHPFan Avatar asked Jan 05 '16 08:01

PHPFan


1 Answers

Something like this should work, here is a JsFiddle Example.

Here I have utilised an existing Bootstrap component, a list-group as an example but you can put any HTML into your popover:

HTML

<!-- body content -->
<div class="container">
  <div class="row">
    <div class="col-xs-12">
      <button type="button" class="btn btn-info" data-toggle="popover" title="Popover title">Toggle popover</button>
    </div>
  </div>
</div>

<!-- loaded popover content -->
<ul id="popover-content" class="list-group" style="display: none">
  <a href="#" class="list-group-item">Edit Event</a>
  <a href="#" class="list-group-item">Invite Members</a>
  <a href="#" class="list-group-item">Delete Event</a>
</ul>

jQuery

$(function() {
  $('[data-toggle="popover"]').popover({
        html: true,
        content: function() {
            return $('#popover-content').html();
        }
  });
});

A very useful library which works great with Bootstrap and will likely aid you in your efforts to create asynchronous calls like inline editing, is X-Editable

like image 51
Matt D. Webb Avatar answered Sep 26 '22 18:09

Matt D. Webb