I have a "Font Awesome" question mark on my webpage. When the user hovers over it, a popover appears via javascript. What's odd (to me), is since the javascript code is AFTER my html code, it works fine.
This works
<div class="margin-top-sm">Enter email: <span class="fa fa-question-circle text--secondary pop" data-container="body" data-toggle="popover" data-placement="right" data-content="My popover text"></span></div>
<script type="text/javascript">
$(".pop").popover({
trigger: "manual",
html: true,
animation: false
})
.on("mouseenter", function () {
var _this = this;
$(this).popover("show");
$(".popover").on("mouseleave", function () {
$(_this).popover('hide');
});
}).on("mouseleave", function () {
var _this = this;
setTimeout(function () {
if (!$(".popover:hover").length) {
$(_this).popover("hide");
}
}, 300);
});
</script>
If I place my javascript ABOVE the html however, it doesn't work.
This doesn't work
<script type="text/javascript">
$(".pop").popover({
trigger: "manual",
html: true,
animation: false
})
.on("mouseenter", function () {
var _this = this;
$(this).popover("show");
$(".popover").on("mouseleave", function () {
$(_this).popover('hide');
});
}).on("mouseleave", function () {
var _this = this;
setTimeout(function () {
if (!$(".popover:hover").length) {
$(_this).popover("hide");
}
}, 300);
});
</script>
<div class="margin-top-sm">Enter email: <span class="fa fa-question-circle text--secondary pop" data-container="body" data-toggle="popover" data-placement="right" data-content="My popover text"></span></div>
I only ask because this is an mvc website & I'd like to toss my javascript within a "Script" @section tags. My "Script" section is at the top of the page in my <head>
section.
So anyway, just curious why this happens?
Thanks