jQuery UI Widgets › Forums › General Discussions › How to "destroy" a widget
This topic contains 4 replies, has 2 voices, and was last updated by sdalby 12 years, 1 month ago.
-
Author
-
Hi,
I have a jqxTree that represents various types of elements.
When one is selected, I wish to display one widget, if another is selected I wish to show another widget at the same position etc.
If we assume that the changing control is showed in the same div, how can I get rid of the old widget before creating the new one?
TIA
/Søren
Hello Søren,
Here is an example which changes the widget when buttons are clicked. However, it has two different div elemets to create the two widgets. You should not have different widgets created from the same div element.
<!DOCTYPE html><html lang="en"><head> <title id='Description'>jQuery CheckBox Sample</title> <link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="jquery-1.7.2.min.js"></script> <script type="text/javascript" src="jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="jqwidgets/jqxcheckbox.js"></script> <script type="text/javascript" src="jqwidgets/jqxradiobutton.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#check").click(function () { $("#jqxradiobutton").remove(); // removes the other widget var found1 = $("body").find("#jqxcheckbox"); if (found1.length == 0) { // checks if the widget has been removed $("#check").before('<div id="jqxcheckbox"></div>'); // if the widget has been removed, its div is inserted in the body again }; $("#jqxcheckbox").jqxCheckBox({ width: 120, height: 25 }); // creates the widget }); $("#radio").click(function () { $("#jqxcheckbox").remove(); var found2 = $("body").find("#jqxradiobutton"); if (found2.length == 0) { $("#check").before('<div id="jqxradiobutton"></div>'); }; $("#jqxradiobutton").jqxRadioButton({ width: 120, height: 25 }); }); }); </script></head><body class='default'> <div id="jqxcheckbox"></div> <div id="jqxradiobutton"></div> <button id="check">Checkbox</button> <button id="radio">Radio button</button></body></html>
Best Regards,
DimitarjqWidgets team
http://www.jqwidgets.com/Thank you so much
Hi Dimitar
Is this a valid approach given that I have many widgets I wish to view based on the selection on a treeview:
function makeDivActive(divName) { contentCell.empty(); contentCell.txt = "<div id=\"" + divName + "\"/>"; }
And then assign the new active control to tag identified by ´divname´.
Thanks in advance
Please disregard this question, I have posted a new one regarding loading contents dynamically.
-
AuthorPosts
You must be logged in to reply to this topic.