javascript - Jquery .click issue -


i facing strange , difficult problem. developing web app, have created few widgets. if click on icon widget editor appear in modular pop-up , user can enter data , data presented on dashboard label. hae "edit" button above label placed on dashboard, wanna add delete button, suppose user add widget on dashboard , later finds doesnt require dashboard clicks on delete button widget should deleted,if user feels wants widget again after deleting, when clicks on icon of particular widget deleted previously, widget should appear again. tried once click on delete button able delete widget when click on icon of widget not able in back.

please me solve issue

just taking guess @ you're looking do, here's example of adding div can close again:

setup:

var widget_markup =     "<div class='widget'>i'm widget. " +     "<span class='close'>close</span>" +     "</div>";  // opens widget, returns true; if widget // open, doesn't open a second , returns false. function openwidget(onclose) {   var widget;    // if there's 1 open, don't   if ($("div.widget").length > 0) {     // open, don't open     return false;   }    // there isn't, add 1   widget = $(widget_markup);   widget.appendto(document.body);   widget.delegate('span.close', 'click', function() {     // remove widget     widget.remove();      // call callback if     if (onclose) {       try {         onclose();       }       catch (e) {       }     }   });    // true = opened widget   return true; } 

use:

$('#btnaddwidget').click(function() {   var button = this;    if (openwidget(handleclose)) {     // opened widget, disable our button     button.disabled = true;   }    function handleclose() {     // widget closd, re-enable button     button.disabled = false;   } }); 

live example

obviously disabling of button relevant if want that; if don't, use this:

setup:

var widget_markup =     "<div class='widget'>i'm widget. " +     "<span class='close'>close</span>" +     "</div>";  // opens widget, returns true; if widget // open, doesn't open a second , returns false. function openwidget(onclose) {   var widget;    widget = $(widget_markup);   widget.appendto(document.body);   widget.delegate('span.close', 'click', function() {     // remove widget     widget.remove();      // call callback if     if (onclose) {       try {         onclose();       }       catch (e) {       }     }   }); } 

use:

$('#btnaddwidget').click(function() {     openwidget(); }); 

live example


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -