Attempting to showcase a button element within a popover, although it is failing to appear

I have implemented a feature where a popover appears when hovering over an inbox icon (font-awesome). However, I am facing an issue with displaying a button on the second row within the popover. The title is showing up fine, but the button is not appearing. I tried wrapping my HTML elements in quotes using jQuery, but it didn't work as expected. Can anyone guide me on what mistake I might be making?

Here is how the current setup looks:

https://i.stack.imgur.com/O1926.png

This is my HTML code snippet:

<div id="ex4">
    <span class="p1 fa-stack fa-2x has-badge" data-count="!">
     <i class="fa fa-inbox"  data-toggle="popover" aria-hidden="true"></i>
    </span>
 </div>

Below is the jQuery function I created:

$(document).ready(function(){
  $('[data-toggle="popover"]').popover({
        placement : 'top',
        trigger : 'hover',
        html: true,
        title:'10 days remaining in your trial!', 
        content:'<div class="button"><button>Close<button></div>'
    });   
});

 

Answer №1

It appears that using

content:'<div class="button"><button>Close<button></div>'
is treating it as text instead of an HTML element. I have found a solution by trying the following code:

Another thing to note is that when binding a popup to a hover event, it will close as soon as you leave the icon. Consider binding it to a click event instead.

<!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="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>

  <div id="ex4">
    <span class="p1 fa-stack fa-2x has-badge" data-count="!">
     <i class="fa fa-inbox"  data-toggle="popover" aria-hidden="true">[icon]</i>
    </span>
 </div>
 
 <script>
$(document).ready(function(){
    $('[data-toggle="popover"]').popover({
        html: true,
        title:'10 days remaining in your trial!',
        content: function () {
             return $("<div class='button'><button>Close</button></div>");
        }
    });   
});
</script>

</body>
</html>

Answer №2

Use this as a guide. It will definitely be beneficial for you. This pop-up appears when the page loads

window.onload = function() {
  document.getElementById('button').onclick = function() {
    document.getElementById('modalOverlay').style.display = 'none'
  };
};
body {
        background: url('https://images.unsplash.com/photo-1492518757308-3eaa20dbb0e2');
        background-repeat: no-repeat;
        background-size: cover;
            font-family: Arial, Helvetica, sans-serif;
        }
    #modalOverlay {
            position: fixed;
            top: 0;
            left: 0;
            background: rgba(0, 0, 0, 0.5);
            z-index: 99999;
            height: 100%;
            width: 100%;
    }
.modalPopup {
            position: absolute;
            top: 30%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: #fff;
            width: 50%;
            padding: 0 0 30px;
            -webkit-box-shadow: 0 2px 10px 3px rgba(0,0,0,.2);
            -moz-box-shadow: 0 2px 10px 3px rgba(0,0,0,.2);
            box-shadow: 0 2px 10px 3px rgba(0,0,0,.2);
    }
.modalContent {padding: 0 2em;}
.headerBar {
        width: 100%;
        background: #edcb04 url(http://cognex.com/gfx/site/bg-global-header.png) repeat-x 0 0;
        margin: 0;
      text-align: center;
    }
.headerBar img {
        margin: 1em .7em;
    }
h1 {
  margin-bottom: .2em;
  font-size: 26px;
  text-transform: capitalize;
}
p {margin: .75em 0 1.5em;}
.buttonStyle {
        border: transparent;
        border-radius: 0;
        background: #6d6d6d;
        color: #eee !important;
        cursor: pointer;
        font-weight: bold;
        font-size: 14px;
        text-transform: uppercase;
        padding: 6px 25px;
        text-decoration: none;
        background: -moz-linear-gradient(top, #6d6d6d 0%, #1e1e1e 100%);
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6d6d6d), color-stop(100%,#1e1e1e));
        background: -webkit-linear-gradient(top, #6d6d6d 0%,#1e1e1e 100%);
        background: -o-linear-gradient(top, #6d6d6d 0%,#1e1e1e 100%);
        background: -ms-linear-gradient(top, #6d6d6d 0%,#1e1e1e 100%);
        background: linear-gradient(to bottom, #6d6d6d 0%,#1e1e1e 100%);
        filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6d6d6d', endColorstr='#1e1e1e',GradientType=0 );
    /*  -webkit-box-shadow: 0 2px 4px 0 #999;
        box-shadow: 0 2px 4px 0 #999; */
        -webkit-transition: all 1s ease;
        -moz-transition: all 1s ease;
        -ms-transition: all 1s ease;
        -o-transition: all 1s ease;
        transition: all 1s ease;
    }
    .buttonStyle:hover {
        background: #1e1e1e;
        color: #fff;
        background: -moz-linear-gradient(top, #1e1e1e 0%, #6d6d6d 100%, #6d6d6d 100%);
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e1e1e), color-stop(100%,#6d6d6d), color-stop(100%,#6d6d6d));
        background: -webkit-linear-gradient(top, #1e1e1e 0%,#6d6d6d 100%,#6d6d6d 100%);
        background: -o-linear-gradient(top, #1e1e1e 0%,#6d6d6d 100%,#6d6d6d 100%);
        background: -ms-linear-gradient(top, #1e1e1e 0%,#6d6d6d 100%,#6d6d6d 100%);
        background: linear-gradient(to bottom, #1e1e1e 0%,#6d6d6d 100%,#6d6d6d 100%);
        filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e1e1e', endColorstr='#6d6d6d',GradientType=0 );
    }
.returnToProfile {text-align: center; margin:3em;}
.returnToProfile a, .returnToProfile a:visited {color: #ddd;}
.returnToProfile a:hover {color: #fff;}
<html>
<head>
<meta charset="utf-8">
<title>Modal popup</title>
  <script type="text/javascript">
    // Place the JS here or just before the BODY close.
    </script>
</head>

<body>
    <div id="modalOverlay">
        <div class="modalPopup">
            <div class="headerBar">
                <img src="https://placehold.it/200x25/edcb04/333333/?text=LOGO" alt="Logo">
            </div>
            <div class="modalContent">
                    <h1>Modal window title here</h1>
                     <p>Modal appears on page load, presents information and is dismissed after the "Close" button is clicked. Styled modal messaging, images and other information here.</p>
                     <button class="buttonStyle" id="button">Close</button>
            </div>
        </div>
    </div>
  <!--p class="returnToProfile"><a href="https://codepen.io/ptamaro" target="_parent">Return to profile</a></p-->
</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Problem with exporting default class in Babel/Jest conflict

Currently, I am facing a challenge while testing the code using jest. The issue seems to be related to babel, especially regarding the export of a default class. Here is an example of the code causing the problem... export default class Test { get() { ...

Using scrollIntoView() in combination with Angular Material's Mat-Menu-Item does not produce the desired result

I am facing an issue with angular material and scrollIntoView({ behavior: 'smooth', block: 'start' }). My goal is to click on a mat-menu-item, which is inside an item in a mat-table, and scroll to a specific HTML tag This is my target ...

Easily transfer files without the need to refresh the page by utilizing the power of AJAX

In my page file-upload.jsp, I have the following code snippet: <form action="" id="frmupload" name="frmupload" method="post" enctype="multipart/form-data"> <input type="file" id="upload_file" name="upload_file" multiple="" /> <in ...

Adjust the size of the embedded iframe to match the dimensions of the containing div

Is there a method to resize the iframe embed code for a vine so that it fits within the boundaries of the enclosing div? The supplied embed code already includes sizing information as shown below: <iframe src="https://vine.co/v/iMJzrThFhDL/embed/simp ...

How can I showcase data retrieved from a function using Ajax Datatable?

I have implemented an Ajax function that retrieves data from a PHP file and displays it in a DataTable. Initially, this setup was working fine. However, when I added a new function to the PHP file, my Ajax function stopped retrieving data from the file. I ...

Implementing the rendering of HTML stored in an array in Angular

I have an array that includes an object with HTML elements which I would like to render in Angular. Here is the array: { name: "rules", key: "rules", value_before: "<tr><td>revisit_in_some_days</td><td>less_then</td>td> ...

The hamburger menu on the navigation bar only functions the first time it is clicked

I've encountered an issue with my hidden menu nav bar. The hamburger and close buttons only work once. Should I organize the events within a function and call it at the end, or perhaps use a loop for the button events? It's worth noting that I d ...

How to toggle the dropdownbox status using jQuery

Just starting with jQuery and I'm looking to enable or disable a dropdown list based on a checkbox. Here's what my html looks like: <select id="dropdown" style="width:200px"> <option value="feedback" name="aft_qst">After Quest&l ...

Utilizing JavaScript to Load an HTML File in a Django Web Development Project

Having a django template, I aim to load an html file into a div based on the value of a select box. The specific target div is shown below: <table id="template" class="table"> Where tables are loaded. </table> There ex ...

Firebase Firestore is returning the dreaded [object Object] rather than the expected plain object

I've created a custom hook called useDocument.js that retrieves data from a firestore collection using a specific ID. However, I'm encountering an issue where it returns [object Object] instead of a plain object. When I attempt to access the nam ...

The jQuery code is executing before the AJAX request is fully processed

$("form#go").submit(function(){ var $this = $(this); var btn = $this.find("button"); btn.text("Searching").attr('disabled','disabled'); $.ajax({ url: type: data: dataType: ...

Display a hidden div on hover using JQUERY

How can I make a hover popup appear when submitting a form, and have it disappear only when the mouse is out of both the popup div and the submit button? Currently, the hover popup shows up but disappears when entering the popup. Can someone assist me in r ...

How come TinyMCE is showing HTML code instead of formatted text?

I have been working on integrating TinyMCE with React on the frontend and django(DRF) on the backend. After saving data from TinyMCE, it retains the HTML tags when displayed back, like this: <p>test</p> <div>Test inside div</div> ...

Having trouble making the menu stay at the top of the page in IE7

Check out the demo here: http://jsfiddle.net/auMd5/ I'm looking to have the blue menu bar stay fixed to the top of the page as you scroll past it, and then return to its original position when scrolling back up. This functionality works in all brows ...

Utilizing React, generate buttons on the fly that trigger the display of their respective

Looking for a way to dynamically display 3 buttons, each of which opens a different modal? I'm struggling to figure out how to properly link the buttons to their respective modals. Here's the code I've attempted so far: Button - Modal Code: ...

Strange Data List Phenomenon

Presented here are two distinct datalists, one containing patient filenumbers and the other containing states. <input type="list" class="form-control" name="patient" list="patient-list" placeholder="Enter Patient file number"> <datali ...

Issue with aligning content vertically in a Bootstrap 3 div

My attempt at vertically aligning text within a div using the following code snippet did not yield the desired result (see fiddle): <div class="container-fluid"> <div class="row"> <div class="col-xs-2"> This conte ...

Combining different HTML table borders

Here is some example code: <!DOCTYPE html> <html> <body> <h4>Creating a table with nested tables:</h4> <table border="1"> <tr> <td>100</td> <td>200</td> <td> </td> < ...

Issue encountered while generating a package using npm init in Node.js

I am currently in the learning process of NodeJs from tutorialspoint(TP). Following instructions provided in this link, I tried to create a package by running the following command: C:\Program Files (x86)\nodejs>npm init This utility will w ...

Tips for setting elevation breakpoints for Paper components in MUI

I'm currently utilizing the MUI5 framework for my Project and I must say it's been great so far. I recently created a login page where I incorporated the Paper Component. Within the Paper Component, I wanted to specify an Elevation level. This i ...