I am showing some information when mouse hovering on glyphicon sign. The code is working now but only for add content
. I want to uses the same JQuery code for edit, delete ..ect. I do not want to repeat the Jquery code again and again.
How to do that?
HTML:
<input name="add" value="1" type="checkbox" />
Add Contents
<a href="#" title="Add" data-content="1- Problem Report. 2- Maintenance Report. 3- Expeses Report. 4- Add Contract. 5-Items">
<span class="glyphicon glyphicon-info-sign" id="add_inf"></span>
</a>
<input name="edit" value="1" type="checkbox" />
Edit Contents
<a href="#" title="Edit" data-content="1- Problem Report. 2- Maintenance Report. 3- Expeses Report. 4- Contract.">
<span class="glyphicon glyphicon-info-sign" id="edit_inf"></span>
</a>
<input name="delete" value="1" type="checkbox" />
Delete Content
<a href="#" title="Delete" data-content="1- Problem Report. 2- Maintenance Report. 3- Expeses Report. 4- Contract. 5-Items">
<span class="glyphicon glyphicon-info-sign" id="delete_inf"></span>
</a>
JQuery:
var $btn2 = $('#add_inf');
$btn2.data('state', 'hover');
var enterShow = function () {
if ($btn2.data('state') === 'hover') {
$btn2.popover('show');
}
};
var exitHide = function () {
if ($btn2.data('state') === 'hover') {
$btn2.popover('hide');
}
};
var clickToggle = function () {
if ($btn2.data('state') === 'hover') {
$btn2.data('state', 'pinned');
} else {
$btn2.data('state', 'hover')
$btn.popover('hover');
}
};
$btn2.popover({ trigger: 'manual' })
.on('mouseenter', enterShow)
.on('mouseleave', exitHide)
.on('click', clickToggle);