admin管理员组文章数量:1405128
I am using tippy.js to generate tooltips in an asp mvc application. I am trying to change the text of the tooltip dynamically depending on another element, a drop down list. The problem I have is that the 'old' tooltips show on top of each other.
Here is my code (simplified):
$(document).on('change', '.partyStatus', function (event) {
event.preventDefault();
event.stopImmediatePropagation(); //stops propagation of click event to other element having the same ID
if (this.value == 5) //Visitor => no autoplete: free text...
{
partyNameInput.className = "form-control partyName tip";
partyNameInput.title = "Please enter the visitor name.";
tooltip('.tip', 'ehs');
}
else {
partyNameInput.className = "form-control autoplete_party partyName tip";
partyNameInput.title = "Type in the first letter of a surname, and pick the person from the list.";
tooltip('.tip', 'ehs');
}
});
The tooltip function:
function tooltip(selector, userTheme) {
tippy(selector, {
theme: userTheme,
position: 'right',
animation: 'scale',
duration: 600
})
}
I am using tippy.js to generate tooltips in an asp mvc application. I am trying to change the text of the tooltip dynamically depending on another element, a drop down list. The problem I have is that the 'old' tooltips show on top of each other.
Here is my code (simplified):
$(document).on('change', '.partyStatus', function (event) {
event.preventDefault();
event.stopImmediatePropagation(); //stops propagation of click event to other element having the same ID
if (this.value == 5) //Visitor => no autoplete: free text...
{
partyNameInput.className = "form-control partyName tip";
partyNameInput.title = "Please enter the visitor name.";
tooltip('.tip', 'ehs');
}
else {
partyNameInput.className = "form-control autoplete_party partyName tip";
partyNameInput.title = "Type in the first letter of a surname, and pick the person from the list.";
tooltip('.tip', 'ehs');
}
});
The tooltip function:
function tooltip(selector, userTheme) {
tippy(selector, {
theme: userTheme,
position: 'right',
animation: 'scale',
duration: 600
})
}
Share
Improve this question
edited Dec 12, 2017 at 16:06
Syl20
asked Dec 12, 2017 at 15:49
Syl20Syl20
1173 silver badges18 bronze badges
2 Answers
Reset to default 3You will need to set the dynamicTitle option to true.
tippy(selector, {
theme: userTheme,
position: 'right',
animation: scale,
dynamicTitle: true
})
Then you can change the title attribute of the element onClick or onHover
element.addEventListener('click', function() {
this.setAttribute('title', 'New tooltip title here!');
})
Source TippyJS docs: https://atomiks.github.io/tippyjs/
For Tippy v6 it's stated in the documentation on how you could 1) get the tippy property and 2) how to set the content.
For example, let's display 'Hide' when the the element has the class 'active', and display 'Show' when the it doesn't have the 'active' class:
$(document).on('click', '.filter', function (){
if( $(this).hasClass('active') ){
this._tippy.setContent('Hide')
}else{
this._tippy.setContent('Show');
}
})
本文标签: javascriptDynamically Change tooltip text (tippyjs)Stack Overflow
版权声明:本文标题:javascript - Dynamically Change tooltip text (tippy.js) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744887571a2630576.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论