admin管理员组文章数量:1387317
$("#id").tooltip({
effect: "slide",
tip: '.tooltip'
});
I want to delete the object created by this code.
"flowplayer jquery tools" plugin
This question has an answer described in the bottom of my post!
See the bottom if you don't wanna loose you time
.
----------UPDATE----------
That should be something like this
The code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ".dtd">
<html><head>
<title>jQuery tooltip</title>
<script src=".3.2/jquery.min.js"></script>
<script src=".1.2/full/jquery.tools.min.js"></script>
<script type="text/javascript">
/******* THIS FUNCTION IS JUST FOR TEST, REMOVE IT LATER *********/
$(document).ready(function() {
$("#_2").tooltip({
effect: "slide",
tip: '.tooltip' ,
position: 'bottom center'
});
});
/******* THIS FUNCTION IS JUST FOR TEST, REMOVE IT LATER *********/
/** The code below is not working as I expect, it doesn't MOVE tooltip **/
var old_id;
//first time - create tooltip
function my_create(id){
$("#"+id).tooltip({
effect: "slide",
tip: '.tooltip',
position: 'bottom center'
});
}
//next times - move tooltip to other element
function my_unlink(id){
$("#"+id).unbind("mouseover");
//todo
}
function my_link(id){
//todo
}
//THE MAIN FUNCTION
function do_tip(new_id){
if(old_id){
my_unlink(old_id);
my_link(new_id);
alert(new_id);
}
else
my_create(new_id);
old_id=new_id;
//new_id.focus();
}
</script>
<style>
.tooltip {
display: none;
background:transparent url(.png);
font-size:14px;
height:70px;
width:160px;
padding:25px;
color:#fff;
}
h1 {
width: 400px;
text-align: center;
background-color: yellow;
}
</style>
</head>
<body>
<h1 onclick="do_tip(this.id)" id="_1">John</h1>
<h1 onclick="do_tip(this.id)" id="_2">Mary</h1>
<h1 onclick="do_tip(this.id)" id="_3">Dan</h1>
<h1 onclick="do_tip(this.id)" id="_4">Paul</h1>
<h1 onclick="do_tip(this.id)" id="_5">Kim</h1>
<div class="tooltip">There should be only one tooltip on a page!</div>
</body></html>
.
---------UPDATE 2----------
Here's the answer
Linking/unlinking jquery object to an element
The moral of this long tale is:
I've been thinking it's a mon, not code or plugin-specific question. I thought that the solution should be as simple as "destroy old tooltip object and then create a new one, attatched to other element"
$("#id").tooltip({
effect: "slide",
tip: '.tooltip'
});
I want to delete the object created by this code.
"flowplayer jquery tools" plugin
This question has an answer described in the bottom of my post!
See the bottom if you don't wanna loose you time
.
----------UPDATE----------
That should be something like this
The code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>
<title>jQuery tooltip</title>
<script src="http://ajax.googleapis./ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="http://cdn.jquerytools/1.1.2/full/jquery.tools.min.js"></script>
<script type="text/javascript">
/******* THIS FUNCTION IS JUST FOR TEST, REMOVE IT LATER *********/
$(document).ready(function() {
$("#_2").tooltip({
effect: "slide",
tip: '.tooltip' ,
position: 'bottom center'
});
});
/******* THIS FUNCTION IS JUST FOR TEST, REMOVE IT LATER *********/
/** The code below is not working as I expect, it doesn't MOVE tooltip **/
var old_id;
//first time - create tooltip
function my_create(id){
$("#"+id).tooltip({
effect: "slide",
tip: '.tooltip',
position: 'bottom center'
});
}
//next times - move tooltip to other element
function my_unlink(id){
$("#"+id).unbind("mouseover");
//todo
}
function my_link(id){
//todo
}
//THE MAIN FUNCTION
function do_tip(new_id){
if(old_id){
my_unlink(old_id);
my_link(new_id);
alert(new_id);
}
else
my_create(new_id);
old_id=new_id;
//new_id.focus();
}
</script>
<style>
.tooltip {
display: none;
background:transparent url(http://flowplayer/tools/img/tooltip/black_arrow_bottom.png);
font-size:14px;
height:70px;
width:160px;
padding:25px;
color:#fff;
}
h1 {
width: 400px;
text-align: center;
background-color: yellow;
}
</style>
</head>
<body>
<h1 onclick="do_tip(this.id)" id="_1">John</h1>
<h1 onclick="do_tip(this.id)" id="_2">Mary</h1>
<h1 onclick="do_tip(this.id)" id="_3">Dan</h1>
<h1 onclick="do_tip(this.id)" id="_4">Paul</h1>
<h1 onclick="do_tip(this.id)" id="_5">Kim</h1>
<div class="tooltip">There should be only one tooltip on a page!</div>
</body></html>
.
---------UPDATE 2----------
Here's the answer
Linking/unlinking jquery object to an element
The moral of this long tale is:
I've been thinking it's a mon, not code or plugin-specific question. I thought that the solution should be as simple as "destroy old tooltip object and then create a new one, attatched to other element"
Share Improve this question edited May 23, 2017 at 12:01 CommunityBot 11 silver badge asked Jan 22, 2010 at 13:10 DanDan 58k44 gold badges122 silver badges162 bronze badges 4- Is this a plugin you're using? If so there might be a way to delete it in the plugins API. – Fermin Commented Jan 22, 2010 at 13:13
- Which plugin is this? Can't answer without knowing what the plugin creates. – Nick Craver Commented Jan 22, 2010 at 13:24
- 3 please specify all the necessary html to run this code, as well as the javascript library and plugin used – bjelli Commented Jan 22, 2010 at 13:24
- how about just don't use this plugin for particular objects? – Darmen Commented Jan 23, 2010 at 8:48
6 Answers
Reset to default 2You write that you want to delete the object created by the code.
What the code does is that first searches for an element with id 'ID' in your page, let's call this "the trigger".
I'm changing one thing in the code here: Instead of selecting the trigger by id 'ID' I select using the class 'do_tooltip_for_this'. This way I can set up a tooltip for multiple triggers at once.
If the user moves the mouse over the trigger, an element with class 'tooltip', that is already present in the page, will be shown and positioned near that trigger. If the user moves the mouse away from the trigger this element is automatically hidden again. This works for several triggers as well, the same tooltip is reused.
You can also hide the tooltip by hand by writing
$('.tooltip').hide();
You can disable the whole behaviour by writing
$(".do_tooltip_for_this").unbind("mouseover");
Here's the whole code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>
<title>jQuery tooltip</title>
<script src="http://ajax.googleapis./ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="http://cdn.jquerytools/1.1.2/full/jquery.tools.min.js"></script>
<script type="text/javascript">
var o;
$(document).ready(function() {
o = $(".do_tooltip_for_this").tooltip({
effect: "slide",
tip: '.tooltip' ,
position: 'bottom center'
});
});
</script>
<style>
.tooltip {
display: none;
background:transparent url(http://flowplayer/tools/img/tooltip/black_arrow_bottom.png);
font-size:12px;
height:70px;
width:160px;
padding:25px;
color:#fff;
}
h1 {
width: 400px;
text-align: center;
background-color: yellow;
}
</style>
</head>
<body>
<h1 title="a tooltip regarding John" class="do_tooltip_for_this">This is John</h1>
<h1 title="a tooltip regarding Paul" class="do_tooltip_for_this">This is Paul</h1>
<h1 title="a tooltip regarding George" class="do_tooltip_for_this">This is George</h1>
<h1 title="a tooltip regarding Ringo" class="do_tooltip_for_this">This is Ringo</h1>
<div class="tooltip"></div>
</body></html>
How about using this:
delete (object_here);
This will remove the javascript objects.
Depends. If you to something like .remove() on it, it actually removes the entire element with that ID from the page.
If you just want to remove the tooltip from it, check out the plugin that you're using. Usually plugins provide a destroy option (the dialog provided by jQuery UI does this).
Unless you're willing to remove the entire element from the page and then recreate it, these is nothing in the core library to do that. If you wanna give that method a go this would get you going in the right direction:
$('#id').replaceWith($('#id').clone());
By default .clone won't copy events and data bound to an element, so that should be a dirty way to get rid of the tooltip. But again, see if your plugin has any built-in way to clean up.
$("#id").tooltip({});
Have you tried that?
by using jQuery you could use .remove()
$("#id").remove(); // will remove element with an id of 'id'
EDITED
it work for someone here. It might also work on you.
// unbind focus and mouseover to cover all the bases just
// incase the tooltip is not being applied to an input
$("#id").unbind("focus");
$("#id").unbind("mouseover");
$("#id").removeData('tooltip');
本文标签: javascriptHow can I delete jquery object at runtimeStack Overflow
版权声明:本文标题:javascript - How can I delete jquery object at runtime? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744549292a2612087.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论