All docs
V19.1
24.1
The page you are viewing does not exist in version 24.1.
23.2
The page you are viewing does not exist in version 23.2.
23.1
The page you are viewing does not exist in version 23.1.
22.2
The page you are viewing does not exist in version 22.2.
22.1
The page you are viewing does not exist in version 22.1.
21.2
The page you are viewing does not exist in version 21.2.
21.1
The page you are viewing does not exist in version 21.1.
20.2
The page you are viewing does not exist in version 20.2.
20.1
The page you are viewing does not exist in version 20.1.
19.2
19.1
18.2
18.1
17.2
A newer version of this page is available. Switch to the current version.

DevExtreme jQuery - Show and Hide the Popover

User Interaction

To specify when the Popover should be shown and hidden, set the showEvent and hideEvent options. These options can accept several events at once as well as an object.

jQuery
JavaScript
HTML
$(function() {
    $("#popoverContainer").dxPopover({
        target: "#image",
        showEvent: 'dxhoverstart',
        hideEvent: 'dxhoverend'
    });
});
<img id="image" src="https://www.devexpress.com/DXR.axd?r=9999_17-FD0Id" />
<div id="popoverContainer">
    <p>Popover content</p>
</div>
Angular
HTML
TypeScript
<img id="image" src="https://www.devexpress.com/DXR.axd?r=9999_17-FD0Id" />
<dx-popover
    target="#image"
    showEvent="dxhoverstart"
    hideEvent="dxhoverend">
    <div *dxTemplate="let data of 'content'">
        <p>Popover content</p>
    </div>
</dx-popover>
import { DxPopoverModule } from "devextreme-angular";
// ...
export class AppComponent {
    // ...
}
@NgModule({
    imports: [
        // ...
        DxPopoverModule
    ],
    // ...
})
ASP.NET MVC Controls
Razor C#
@(Html.DevExtreme().Popover()
    .Target("#image")
    .ShowEvent("dxhoverstart")
    .HideEvent("dxhoverend")
    .ContentTemplate(@<text>
        <p>Popover content</p>
    </text>)
)
<img id="image" src="https://www.devexpress.com/DXR.axd?r=9999_17-FD0Id" />

View Demo

The Popover can also be hidden when a user clicks outside it. To control this behavior of the Popover, use the closeOnOutsideClick option.

jQuery
JavaScript
HTML
$(function() {
    $("#popoverContainer").dxPopover({
        target: "#image",
        showEvent: 'dxhoverstart',
        hideEvent: 'dxhoverend',
        closeOnOutsideClick: false
    });
});
<img id="image" src="https://www.devexpress.com/DXR.axd?r=9999_17-FD0Id" />
<div id="popoverContainer">
    <p>Popover content</p>
</div>
Angular
HTML
TypeScript
<img id="image" src="https://www.devexpress.com/DXR.axd?r=9999_17-FD0Id" />
<dx-popover
    target="#image"
    showEvent="dxhoverstart"
    hideEvent="dxhoverend"
    [closeOnOutsideClick]="false">
    <div *dxTemplate="let data of 'content'">
        <p>Popover content</p>
    </div>
</dx-popover>
import { DxPopoverModule } from "devextreme-angular";
// ...
export class AppComponent {
    // ...
}
@NgModule({
    imports: [
        // ...
        DxPopoverModule
    ],
    // ...
})
ASP.NET MVC Controls
Razor C#
@(Html.DevExtreme().Popover()
    .Target("#image")
    .ShowEvent("dxhoverstart")
    .HideEvent("dxhoverend")
    .ContentTemplate(@<text>
        <p>Popover content</p>
    </text>)
    .CloseOnOutsideClick(false)
)
<img id="image" src="https://www.devexpress.com/DXR.axd?r=9999_17-FD0Id" />

API

NOTE
In this article, the Button widget is used to demonstrate how to show and hide the Popover. This choice is made for purely demonstrational purposes, and you can do the same operations using another widget following the same guidelines.

To show or hide the Popover programmatically, call the show() or hide() method. The same thing can be done using the toggle(showing) method. Pass true or false to this method to show or hide the Popover, respectively. This approach is more typical of jQuery and ASP.NET MVC Controls.

jQuery
JavaScript
HTML
$(function() {
    $("#popoverContainer").dxPopover({
        target: "#image"
    });

    $("#showButton").dxButton({
        text: "Show the Popover", 
        onClick: function () {
            $("#popoverContainer").dxPopover("show");
            // ===== or =====
            $("#popoverContainer").dxPopover("toggle", true);
        } 
    });

    $("#hideButton").dxButton({
        text: "Hide the Popover", 
        onClick: function () {
            $("#popoverContainer").dxPopover("hide");
            // ===== or =====
            $("#popoverContainer").dxPopover("toggle", false);
        } 
    });
});
<img id="image" src="https://www.devexpress.com/DXR.axd?r=9999_17-FD0Id" />
<div id="popoverContainer">
    <p>Popover content</p>
</div>
<div id="showButton"></div>
<div id="hideButton"></div>
ASP.NET MVC Controls
Razor C#
@(Html.DevExtreme().Popover()
    .ID("popover")
    .Target("#image")
    .ContentTemplate(@<text>
        <p>Popover content</p>
    </text>)
)
<img id="image" src="https://www.devexpress.com/DXR.axd?r=9999_17-FD0Id" />

@(Html.DevExtreme().Button()
    .ID("showButton")
    .Text("Show the Popover")
    .OnClick("showPopover")
)

@(Html.DevExtreme().Button()
    .ID("hideButton")
    .Text("Hide the Popover")
    .OnClick("hidePopover")
)

<script type="text/javascript">
    function showPopover () {
        $("#popover").dxPopover("show");
        // ===== or =====
        $("#popover").dxPopover("toggle", true);
    }

    function hidePopover () {
        $("#popover").dxPopover("hide");
        // ===== or =====
        $("#popover").dxPopover("toggle", false);
    } 
</script>

The show() method called without arguments shows the Popover for the target specified beforehand. If you need to change the target once, call the show(target) method.

jQuery
JavaScript
$(function() {
    // ...
    $("#showButton").dxButton({
        text: "Show the Popover", 
        onClick: function () {
            $("#popoverContainer").dxPopover("show", "#newTarget");
        } 
    });
});
ASP.NET MVC Controls
Razor C#
// ...

<script type="text/javascript">
    function showPopover () {
        $("#popover").dxPopover("show", "#newTarget");
    }
    // ...
</script>

With Angular, AngularJS, or Knockout, use a different technique. Bind the visible property of the Popover widget to a component property (in Angular), a scope property (in AngularJS), or an observable variable (in Knockout). After that, change them, and the Popover will appear or disappear.

Angular
HTML
TypeScript
<img id="image" src="https://www.devexpress.com/DXR.axd?r=9999_17-FD0Id" />
<dx-popover
    target="#image"
    [visible]="isPopoverVisible">
    <div *dxTemplate="let data of 'content'">
        <p>Popover content</p>
    </div>
</dx-popover>
<dx-button
    text="Show the Popover"
    (onClick)="isPopoverVisible = true">
</dx-button>
<dx-button
    text="Hide the Popover"
    (onClick)="isPopoverVisible = false">
</dx-button>
import { DxPopoverModule, DxButtonModule } from "devextreme-angular";
// ...
export class AppComponent {
    isPopoverVisible: boolean = false;
}
@NgModule({
    imports: [
        // ...
        DxPopoverModule
    ],
    // ...
})
AngularJS
HTML
JavaScript
<div ng-controller="DemoController">
    <div dx-popover="{
        target: '#image',
        bindingOptions: {
            visible: 'isPopoverVisible'
        }
    }">
        <p>Popover Content</p>
    </div>
    <div dx-button="{
        text: 'Show the Popover',
        onClick: showPopover
    }"></div>
    <div dx-button="{
        text: 'Hide the Popover',
        onClick: hidePopover
    }"></div>
</div>
angular.module('DemoApp', ['dx'])
    .controller('DemoController', function DemoController($scope) {
        $scope.isPopoverVisible = false;
        $scope.showPopover = function () {
            $scope.isPopoverVisible = true;
        };
        $scope.hidePopover = function () {
            $scope.isPopoverVisible = false;
        };
    });
Knockout
HTML
JavaScript
<div data-bind="dxPopover: {
    target: '#image',
    visible: isPopoverVisible
}">
    <p>Popover Content</p>
</div>
<div data-bind="dxButton: {
    text: 'Show the Popover',
    onClick: function (e) {
        e.model.isPopoverVisible(true);
    }
}"></div>
<div data-bind="dxButton: {
    text: 'Hide the Popover',
    onClick: function (e) {
        e.model.isPopoverVisible(false);
    }
}"></div>
var viewModel = {
    isPopoverVisible: ko.observable(false)
};

ko.applyBindings(viewModel);

Events

To execute certain commands before or after the Popover was shown/hidden, handle the showing, shown, hiding or hidden event. If the event handling function is not going to be changed during the lifetime of the widget, assign it to the corresponding onEventName option when you configure the widget.

jQuery
JavaScript
$(function () {
    $("#popoverContainer").dxPopover({
        // ...
        onShowing: function (e) {
            // Handler of the "showing" event
        },
        onShown: function (e) {
            // Handler of the "shown" event
        },
        onHiding: function (e) {
            // Handler of the "hiding" event
        },
        onHidden: function (e) {
            // Handler of the "hidden" event
        }
    });
});
Angular
HTML
TypeScript
<dx-popover ...
    (onShowing)="onShowing($event)"
    (onShown)="onShown($event)"
    (onHiding)="onHiding($event)"
    (onHidden)="onHidden($event)">
</dx-popover>
import { DxPopoverModule } from "devextreme-angular";
// ...
export class AppComponent {
    onShowing (e) {
        // Handler of the "showing" event
    },
    onShown (e) {
        // Handler of the "shown" event
    },
    onHiding (e) {
        // Handler of the "hiding" event
    },
    onHidden (e) {
        // Handler of the "hidden" event
    }
}
@NgModule({
    imports: [
        // ...
        DxPopoverModule
    ],
    // ...
})
ASP.NET MVC Controls
Razor C#
@(Html.DevExtreme().Popover()
    // ...
    .OnShowing("popover_onShowing")
    .OnShown("popover_onShown")
    .OnHiding("popover_onHiding")
    .OnHidden("popover_onHidden")
)

<script type="text/javascript">
    function popover_onShowing (e) {
        // Handler of the "showing" event
    },
    function popover_onShown (e) {
        // Handler of the "shown" event
    },
    function popover_onHiding (e) {
        // Handler of the "hiding" event
    },
    function popover_onHidden (e) {
        // Handler of the "hidden" event
    }
</script>

If you are going to change event handlers at runtime, or if you need to attach several handlers to a single event, subscribe to the events using the on(eventName, eventHandler) method. This approach is more typical of jQuery.

JavaScript
var hiddenEventHandler1 = function (e) {
    // First handler of the "hidden" event
};

var hiddenEventHandler2 = function (e) {
    // Second handler of the "hidden" event
};

$("#popoverContainer").dxPopover("instance")
    .on("hidden", hiddenEventHandler1)
    .on("hidden", hiddenEventHandler2);
See Also