SlideShare a Scribd company logo
1 of 3
Download to read offline
22/8/2014 How to remove a bootstrap modal that's been inserted via jQuery? - Stack Overflow
http://stackoverflow.com/questions/16533514/how-to-remove-a-bootstrap-modal-thats-been-inserted-via-jquery 1/3
Take the 2­minute tour   ×
I decided I wanted to have a script that I could use if I needed to insert custom Bootstrap modals. I didn't
want to have the empty static Bootsrap modal HTML sat in the bottom of every page if it wouldn't always
be utilized.
So, this may be the wrong way of going about it, but this was my attempt. I create a variable which is the
modal 'shell' html. Then, when I click a device item, this is appended to the body. I have some content
then cloned and appended to header and body of the modal. All working fine. But I can't remove the
modal once it's closed. This is something to do with the fact that I insert the HTML via JS, as the remove
works fine if the Modal shell HTML exists statically in my HTML page.
HTML:
<ul>
    <li class="span4 device">
        <div class="inner">
            <h3>Device 4</h3>
            <div class="device­product">
                <img class="device­image" src="img/placeholder­holding­image.png" alt="Holding Image" />
                <a href="#" class="hide">Troubleshoot this item</a>
                <a href="#" class="hide">How to use this product</a>
            </div>
            <div class="device­details">
                <div class="control­group">
                    <label class="control­label">Device Type:</label>
                    <span class="field">Really cool device</span>
                </div>
                <!­­ Small amount of hidden additional information ­­>
                <div class="control­group hide">
                    <label class="control­label">Device ID:</label>
                    <span class="field">123456</span>
                </div>
            </div>
        </div>
    </li>
</ul>
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no
registration required.
How to remove a bootstrap modal that's been inserted via jQuery?
sign up
 
log in
 
tour
 
help 
 
careers 2.0
 
22/8/2014 How to remove a bootstrap modal that's been inserted via jQuery? - Stack Overflow
http://stackoverflow.com/questions/16533514/how-to-remove-a-bootstrap-modal-thats-been-inserted-via-jquery 2/3
davidpauljunior
4,512 1 6 26
1 Answer
thefrontender
1,339 5 16
jQuery:
var customModal = $(
    '<div class="custom­modal modal hide fade" tabindex="­1" role="dialog" aria­hidden="true">  
        <div class="modal­header"><button type="button" class="close" data­dismiss="modal" aria­hidden="true">×</button></
        <div class="modal­body"></div> 
        <div class="modal­footer"><button class="btn" data­dismiss="modal">Close</button></div> 
    </div>'
);
$('.device').click(function(){
    $('body').append(customModal);
    $(this).find($('h3')).clone().appendTo('.custom­modal .modal­header');
    $(this).find('.device­product, .device­details').clone().appendTo('.custom­modal .modal­body');
    $('.custom­modal .hide').show();
    $('.custom­modal').modal();
});
 $('.custom­modal').on('hidden', function(){
    $(this).remove();
});
So really it's just the remove() I'm struggling with. But also, any comments on whether I'm going about this
in a wrong / inefficient way are always helpful for learning!
jquery   twitter­bootstrap
edited May 14 '13 at 3:53 asked May 14 '13 at 0:59
You're attempting to bind the event handler for the  hidden event before the  .custom­modal div is
added to the DOM, so the event handler is never bound to anything.
You can do this two ways.
1.  Delegate the  hidden event handler so that the document is always listening for  hidden events
originating from any element with a class of custom­modal:
$(document).on('hidden', '.custom­modal', function () {
    $(this).remove();
});
2.  Bind the event handler after you've added the modal div to the DOM:
$('.device').click(function(){
    // Push the modal markup into the DOM
    $('body').append(customModal);
    // Now that it's in the DOM we can find it and bind an event handler
    $('.custom­modal').on('hidden', function () {
        $(this).remove();
    });
    // Continue with other init tasks
    $(this).find('h3').clone().appendTo('.custom­modal .modal­header');
    $(this).find('.device­product, .device­details').clone().appendTo('.custom­modal .modal­body');
    $('.custom­modal .hide').show();
    $('.custom­modal').modal();
});
Option 1 is preferable, especially if there's a chance that multiple modals will be opened.
edited May 14 '13 at 1:30 answered May 14 '13 at 1:25
    This is removing the  .custom­modal div from the DOM, but I have a separate issue, where when the
modal is triggered again, it still contains the appended content from the previous trigger. –   davidpauljunior
May 14 '13 at 1:53 
add a comment
22/8/2014 How to remove a bootstrap modal that's been inserted via jQuery? - Stack Overflow
http://stackoverflow.com/questions/16533514/how-to-remove-a-bootstrap-modal-thats-been-inserted-via-jquery 3/3
May 14 '13 at 1:53 
    You haven't described this 'separate issue' in the question. Do you have a test page or a JSFiddle you can
share? –  thefrontender May 14 '13 at 2:51
    Sorry for missing this in the question, I assumed that the removal of the modal would remove any attached
appended content. I've also tried this:  $(document).on('hidden', '.modal', function () {   
$(this).removeData('modal'); }); but to no avail. JSFiddle is here:
jsfiddle.net/davidpauljunior/rMyMy –   davidpauljunior  May 14 '13 at 4:06
1   Found it: stop wrapping  customModal as a jQuery object. Pass it as a string instead. e.g. customModal
= '<div class=...' When you turned it into a jQuery object, it still exists after you take it out of the DOM and
continues to receive amendments. –  thefrontender May 14 '13 at 4:22 
1   Updated JSFIddle jsfiddle.net/thefrontender/rMyMy/3 Wrapping the markup in jQuery turned it into a DOM
fragment assigned to the customModal variable. Calling  remove pulled the elements out of the DOM but
the amended DOM Fragment continued to exist in the variable customModal which would get amended to
the DOM again the next time around, and it's changed contents persisted. –  thefrontender May 14 '13 at
4:33
show 1 more comment
Not the answer you're looking for? Browse other questions tagged  jquery  
twitter­bootstrap  or ask your own question.

More Related Content

What's hot

Beyond DOM Manipulations: Building Stateful Modules with Events and Promises
Beyond DOM Manipulations: Building Stateful Modules with Events and PromisesBeyond DOM Manipulations: Building Stateful Modules with Events and Promises
Beyond DOM Manipulations: Building Stateful Modules with Events and PromisesCrashlytics
 
jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuffjeresig
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to JqueryAmzad Hossain
 
Rapid Testing, Rapid Development
Rapid Testing, Rapid DevelopmentRapid Testing, Rapid Development
Rapid Testing, Rapid Developmentmennovanslooten
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overviewjeresig
 
Debugging War Stories & Strategies to Survive on RejectJS 2014
Debugging War Stories & Strategies to Survive on RejectJS 2014Debugging War Stories & Strategies to Survive on RejectJS 2014
Debugging War Stories & Strategies to Survive on RejectJS 2014Johannes Weber
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterpriseDave Artz
 
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...JavaScripters Community
 
Writing JavaScript that doesn't suck
Writing JavaScript that doesn't suckWriting JavaScript that doesn't suck
Writing JavaScript that doesn't suckRoss Bruniges
 
モバイル検索とアプリ
モバイル検索とアプリモバイル検索とアプリ
モバイル検索とアプリKenichi Suzuki
 
Accessibility - A feature you can build
Accessibility - A feature you can buildAccessibility - A feature you can build
Accessibility - A feature you can buildMonika Piotrowicz
 
jQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days TorontojQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days TorontoRalph Whitbeck
 
Professional web development with libraries
Professional web development with librariesProfessional web development with libraries
Professional web development with librariesChristian Heilmann
 
MVC pattern for widgets
MVC pattern for widgetsMVC pattern for widgets
MVC pattern for widgetsBehnam Taraghi
 
Collective.amberjack ploneconf2010
Collective.amberjack ploneconf2010Collective.amberjack ploneconf2010
Collective.amberjack ploneconf2010Massimo Azzolini
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & AngularAlexe Bogdan
 
jQuery Conference Chicago - September 2014
jQuery Conference Chicago - September 2014jQuery Conference Chicago - September 2014
jQuery Conference Chicago - September 2014dmethvin
 

What's hot (20)

Beyond DOM Manipulations: Building Stateful Modules with Events and Promises
Beyond DOM Manipulations: Building Stateful Modules with Events and PromisesBeyond DOM Manipulations: Building Stateful Modules with Events and Promises
Beyond DOM Manipulations: Building Stateful Modules with Events and Promises
 
jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuff
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
 
Rapid Testing, Rapid Development
Rapid Testing, Rapid DevelopmentRapid Testing, Rapid Development
Rapid Testing, Rapid Development
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overview
 
Debugging War Stories & Strategies to Survive on RejectJS 2014
Debugging War Stories & Strategies to Survive on RejectJS 2014Debugging War Stories & Strategies to Survive on RejectJS 2014
Debugging War Stories & Strategies to Survive on RejectJS 2014
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] Enterprise
 
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
 
React django
React djangoReact django
React django
 
Writing JavaScript that doesn't suck
Writing JavaScript that doesn't suckWriting JavaScript that doesn't suck
Writing JavaScript that doesn't suck
 
モバイル検索とアプリ
モバイル検索とアプリモバイル検索とアプリ
モバイル検索とアプリ
 
Accessibility - A feature you can build
Accessibility - A feature you can buildAccessibility - A feature you can build
Accessibility - A feature you can build
 
jQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days TorontojQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days Toronto
 
Professional web development with libraries
Professional web development with librariesProfessional web development with libraries
Professional web development with libraries
 
MVC pattern for widgets
MVC pattern for widgetsMVC pattern for widgets
MVC pattern for widgets
 
FuncUnit
FuncUnitFuncUnit
FuncUnit
 
Collective.amberjack ploneconf2010
Collective.amberjack ploneconf2010Collective.amberjack ploneconf2010
Collective.amberjack ploneconf2010
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & Angular
 
jQuery Conference Chicago - September 2014
jQuery Conference Chicago - September 2014jQuery Conference Chicago - September 2014
jQuery Conference Chicago - September 2014
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 

Viewers also liked

Presentación Ana Cristina Umaña
Presentación Ana Cristina UmañaPresentación Ana Cristina Umaña
Presentación Ana Cristina UmañaCris Umaña
 
Une bulle sur le GIF animé ? GIPHY lève 55 millions de dollars sans avoir de...
Une bulle sur le GIF animé ? GIPHY lève 55  millions de dollars sans avoir de...Une bulle sur le GIF animé ? GIPHY lève 55  millions de dollars sans avoir de...
Une bulle sur le GIF animé ? GIPHY lève 55 millions de dollars sans avoir de...Antoine Wintrebert
 
2.º congresso internacional de serviço social: Presentation from David N Jone...
2.º congresso internacional de serviço social: Presentation from David N Jone...2.º congresso internacional de serviço social: Presentation from David N Jone...
2.º congresso internacional de serviço social: Presentation from David N Jone...IFSW
 
البحث في الانترنت
البحث في الانترنتالبحث في الانترنت
البحث في الانترنتتقانة
 
Les outils d'un growth hacker, par Julien Le Coupanec
Les outils d'un growth hacker, par Julien Le CoupanecLes outils d'un growth hacker, par Julien Le Coupanec
Les outils d'un growth hacker, par Julien Le CoupanecTheFamily
 
листок спостереження
листок спостереженнялисток спостереження
листок спостереженняMARO51
 
Comment améliorer votre rétention: Case studies - Julien Le Coupanec, Growth ...
Comment améliorer votre rétention: Case studies - Julien Le Coupanec, Growth ...Comment améliorer votre rétention: Case studies - Julien Le Coupanec, Growth ...
Comment améliorer votre rétention: Case studies - Julien Le Coupanec, Growth ...TheFamily
 
TheFamily: The Founder's Dilemma, by Oussama Ammar, Partner at TheFamily
TheFamily: The Founder's Dilemma, by Oussama Ammar, Partner at TheFamilyTheFamily: The Founder's Dilemma, by Oussama Ammar, Partner at TheFamily
TheFamily: The Founder's Dilemma, by Oussama Ammar, Partner at TheFamilyTheFamily
 
Server Virtualization Sentrana Seminar
Server Virtualization   Sentrana SeminarServer Virtualization   Sentrana Seminar
Server Virtualization Sentrana Seminarbryanrandol
 

Viewers also liked (16)

Presentación Ana Cristina Umaña
Presentación Ana Cristina UmañaPresentación Ana Cristina Umaña
Presentación Ana Cristina Umaña
 
Presentación2
Presentación2Presentación2
Presentación2
 
Para portafolio de evidencia.
Para portafolio de evidencia.Para portafolio de evidencia.
Para portafolio de evidencia.
 
Une bulle sur le GIF animé ? GIPHY lève 55 millions de dollars sans avoir de...
Une bulle sur le GIF animé ? GIPHY lève 55  millions de dollars sans avoir de...Une bulle sur le GIF animé ? GIPHY lève 55  millions de dollars sans avoir de...
Une bulle sur le GIF animé ? GIPHY lève 55 millions de dollars sans avoir de...
 
LiPP Launch The Family
LiPP Launch The FamilyLiPP Launch The Family
LiPP Launch The Family
 
2.º congresso internacional de serviço social: Presentation from David N Jone...
2.º congresso internacional de serviço social: Presentation from David N Jone...2.º congresso internacional de serviço social: Presentation from David N Jone...
2.º congresso internacional de serviço social: Presentation from David N Jone...
 
كيفية انشاء Qr
كيفية انشاء Qrكيفية انشاء Qr
كيفية انشاء Qr
 
Prolactinoma
Prolactinoma Prolactinoma
Prolactinoma
 
البحث في الانترنت
البحث في الانترنتالبحث في الانترنت
البحث في الانترنت
 
Les outils d'un growth hacker, par Julien Le Coupanec
Les outils d'un growth hacker, par Julien Le CoupanecLes outils d'un growth hacker, par Julien Le Coupanec
Les outils d'un growth hacker, par Julien Le Coupanec
 
листок спостереження
листок спостереженнялисток спостереження
листок спостереження
 
Hiperprolactinemia y prolactinoma
Hiperprolactinemia y prolactinomaHiperprolactinemia y prolactinoma
Hiperprolactinemia y prolactinoma
 
Comment améliorer votre rétention: Case studies - Julien Le Coupanec, Growth ...
Comment améliorer votre rétention: Case studies - Julien Le Coupanec, Growth ...Comment améliorer votre rétention: Case studies - Julien Le Coupanec, Growth ...
Comment améliorer votre rétention: Case studies - Julien Le Coupanec, Growth ...
 
TheFamily: The Founder's Dilemma, by Oussama Ammar, Partner at TheFamily
TheFamily: The Founder's Dilemma, by Oussama Ammar, Partner at TheFamilyTheFamily: The Founder's Dilemma, by Oussama Ammar, Partner at TheFamily
TheFamily: The Founder's Dilemma, by Oussama Ammar, Partner at TheFamily
 
Diuresis Hídrica
Diuresis HídricaDiuresis Hídrica
Diuresis Hídrica
 
Server Virtualization Sentrana Seminar
Server Virtualization   Sentrana SeminarServer Virtualization   Sentrana Seminar
Server Virtualization Sentrana Seminar
 

Similar to Test slideshare document

How I got started in JavaScript
How I got started in JavaScriptHow I got started in JavaScript
How I got started in JavaScriptLim Chee Aun
 
Make your Backbone Application dance
Make your Backbone Application danceMake your Backbone Application dance
Make your Backbone Application danceNicholas Valbusa
 
Joomla Day UK 2009 Template Design Presentation
Joomla Day UK 2009 Template Design PresentationJoomla Day UK 2009 Template Design Presentation
Joomla Day UK 2009 Template Design PresentationChris Davenport
 
Joomla! Day UK 2009 Template Design
Joomla! Day UK 2009 Template DesignJoomla! Day UK 2009 Template Design
Joomla! Day UK 2009 Template DesignAndy Wallace
 
Jquery tutorial-beginners
Jquery tutorial-beginnersJquery tutorial-beginners
Jquery tutorial-beginnersIsfand yar Khan
 
Learning from the Best jQuery Plugins
Learning from the Best jQuery PluginsLearning from the Best jQuery Plugins
Learning from the Best jQuery PluginsMarc Grabanski
 
Inverting Dependencies
Inverting DependenciesInverting Dependencies
Inverting DependenciesLuc Trudeau
 
Iasi code camp 12 october 2013 shadow dom - mihai bîrsan
Iasi code camp 12 october 2013   shadow dom - mihai bîrsanIasi code camp 12 october 2013   shadow dom - mihai bîrsan
Iasi code camp 12 october 2013 shadow dom - mihai bîrsanCodecamp Romania
 
How to Develop Your First Ever Joomla Template?
How to Develop Your First Ever Joomla Template?How to Develop Your First Ever Joomla Template?
How to Develop Your First Ever Joomla Template?damienwoods
 
Advanced Module development
Advanced Module developmentAdvanced Module development
Advanced Module developmentdrupalindia
 
How to Build Responsive Bootstrap Themes Using Drupal
How to Build Responsive Bootstrap Themes Using DrupalHow to Build Responsive Bootstrap Themes Using Drupal
How to Build Responsive Bootstrap Themes Using DrupalDrupalGeeks
 
With Great Nerdery Comes Great Responsibility
With Great Nerdery Comes Great Responsibility With Great Nerdery Comes Great Responsibility
With Great Nerdery Comes Great Responsibility John Anderson
 
JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery維佋 唐
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupalBlackCatWeb
 
Web Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationWeb Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationAndrew Rota
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Javascript for the c# developer
Javascript for the c# developerJavascript for the c# developer
Javascript for the c# developerSalvatore Fazio
 

Similar to Test slideshare document (20)

How I got started in JavaScript
How I got started in JavaScriptHow I got started in JavaScript
How I got started in JavaScript
 
Make your Backbone Application dance
Make your Backbone Application danceMake your Backbone Application dance
Make your Backbone Application dance
 
Joomla Day UK 2009 Template Design Presentation
Joomla Day UK 2009 Template Design PresentationJoomla Day UK 2009 Template Design Presentation
Joomla Day UK 2009 Template Design Presentation
 
Joomla! Day UK 2009 Template Design
Joomla! Day UK 2009 Template DesignJoomla! Day UK 2009 Template Design
Joomla! Day UK 2009 Template Design
 
Jquery tutorial-beginners
Jquery tutorial-beginnersJquery tutorial-beginners
Jquery tutorial-beginners
 
Learning from the Best jQuery Plugins
Learning from the Best jQuery PluginsLearning from the Best jQuery Plugins
Learning from the Best jQuery Plugins
 
Taking your Web App for a walk
Taking your Web App for a walkTaking your Web App for a walk
Taking your Web App for a walk
 
Joomla! Template for Beginners
Joomla! Template for BeginnersJoomla! Template for Beginners
Joomla! Template for Beginners
 
Inverting Dependencies
Inverting DependenciesInverting Dependencies
Inverting Dependencies
 
Iasi code camp 12 october 2013 shadow dom - mihai bîrsan
Iasi code camp 12 october 2013   shadow dom - mihai bîrsanIasi code camp 12 october 2013   shadow dom - mihai bîrsan
Iasi code camp 12 october 2013 shadow dom - mihai bîrsan
 
How to Develop Your First Ever Joomla Template?
How to Develop Your First Ever Joomla Template?How to Develop Your First Ever Joomla Template?
How to Develop Your First Ever Joomla Template?
 
Advanced Module development
Advanced Module developmentAdvanced Module development
Advanced Module development
 
How to Build Responsive Bootstrap Themes Using Drupal
How to Build Responsive Bootstrap Themes Using DrupalHow to Build Responsive Bootstrap Themes Using Drupal
How to Build Responsive Bootstrap Themes Using Drupal
 
With Great Nerdery Comes Great Responsibility
With Great Nerdery Comes Great Responsibility With Great Nerdery Comes Great Responsibility
With Great Nerdery Comes Great Responsibility
 
JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupal
 
Web Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationWeb Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing Combination
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Javascript for the c# developer
Javascript for the c# developerJavascript for the c# developer
Javascript for the c# developer
 
Html5 History-API
Html5 History-APIHtml5 History-API
Html5 History-API
 

Recently uploaded

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

Test slideshare document

  • 1. 22/8/2014 How to remove a bootstrap modal that's been inserted via jQuery? - Stack Overflow http://stackoverflow.com/questions/16533514/how-to-remove-a-bootstrap-modal-thats-been-inserted-via-jquery 1/3 Take the 2­minute tour   × I decided I wanted to have a script that I could use if I needed to insert custom Bootstrap modals. I didn't want to have the empty static Bootsrap modal HTML sat in the bottom of every page if it wouldn't always be utilized. So, this may be the wrong way of going about it, but this was my attempt. I create a variable which is the modal 'shell' html. Then, when I click a device item, this is appended to the body. I have some content then cloned and appended to header and body of the modal. All working fine. But I can't remove the modal once it's closed. This is something to do with the fact that I insert the HTML via JS, as the remove works fine if the Modal shell HTML exists statically in my HTML page. HTML: <ul>     <li class="span4 device">         <div class="inner">             <h3>Device 4</h3>             <div class="device­product">                 <img class="device­image" src="img/placeholder­holding­image.png" alt="Holding Image" />                 <a href="#" class="hide">Troubleshoot this item</a>                 <a href="#" class="hide">How to use this product</a>             </div>             <div class="device­details">                 <div class="control­group">                     <label class="control­label">Device Type:</label>                     <span class="field">Really cool device</span>                 </div>                 <!­­ Small amount of hidden additional information ­­>                 <div class="control­group hide">                     <label class="control­label">Device ID:</label>                     <span class="field">123456</span>                 </div>             </div>         </div>     </li> </ul> Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required. How to remove a bootstrap modal that's been inserted via jQuery? sign up   log in   tour   help    careers 2.0  
  • 2. 22/8/2014 How to remove a bootstrap modal that's been inserted via jQuery? - Stack Overflow http://stackoverflow.com/questions/16533514/how-to-remove-a-bootstrap-modal-thats-been-inserted-via-jquery 2/3 davidpauljunior 4,512 1 6 26 1 Answer thefrontender 1,339 5 16 jQuery: var customModal = $(     '<div class="custom­modal modal hide fade" tabindex="­1" role="dialog" aria­hidden="true">           <div class="modal­header"><button type="button" class="close" data­dismiss="modal" aria­hidden="true">×</button></         <div class="modal­body"></div>          <div class="modal­footer"><button class="btn" data­dismiss="modal">Close</button></div>      </div>' ); $('.device').click(function(){     $('body').append(customModal);     $(this).find($('h3')).clone().appendTo('.custom­modal .modal­header');     $(this).find('.device­product, .device­details').clone().appendTo('.custom­modal .modal­body');     $('.custom­modal .hide').show();     $('.custom­modal').modal(); });  $('.custom­modal').on('hidden', function(){     $(this).remove(); }); So really it's just the remove() I'm struggling with. But also, any comments on whether I'm going about this in a wrong / inefficient way are always helpful for learning! jquery   twitter­bootstrap edited May 14 '13 at 3:53 asked May 14 '13 at 0:59 You're attempting to bind the event handler for the  hidden event before the  .custom­modal div is added to the DOM, so the event handler is never bound to anything. You can do this two ways. 1.  Delegate the  hidden event handler so that the document is always listening for  hidden events originating from any element with a class of custom­modal: $(document).on('hidden', '.custom­modal', function () {     $(this).remove(); }); 2.  Bind the event handler after you've added the modal div to the DOM: $('.device').click(function(){     // Push the modal markup into the DOM     $('body').append(customModal);     // Now that it's in the DOM we can find it and bind an event handler     $('.custom­modal').on('hidden', function () {         $(this).remove();     });     // Continue with other init tasks     $(this).find('h3').clone().appendTo('.custom­modal .modal­header');     $(this).find('.device­product, .device­details').clone().appendTo('.custom­modal .modal­body');     $('.custom­modal .hide').show();     $('.custom­modal').modal(); }); Option 1 is preferable, especially if there's a chance that multiple modals will be opened. edited May 14 '13 at 1:30 answered May 14 '13 at 1:25     This is removing the  .custom­modal div from the DOM, but I have a separate issue, where when the modal is triggered again, it still contains the appended content from the previous trigger. –   davidpauljunior May 14 '13 at 1:53  add a comment
  • 3. 22/8/2014 How to remove a bootstrap modal that's been inserted via jQuery? - Stack Overflow http://stackoverflow.com/questions/16533514/how-to-remove-a-bootstrap-modal-thats-been-inserted-via-jquery 3/3 May 14 '13 at 1:53      You haven't described this 'separate issue' in the question. Do you have a test page or a JSFiddle you can share? –  thefrontender May 14 '13 at 2:51     Sorry for missing this in the question, I assumed that the removal of the modal would remove any attached appended content. I've also tried this:  $(document).on('hidden', '.modal', function () {    $(this).removeData('modal'); }); but to no avail. JSFiddle is here: jsfiddle.net/davidpauljunior/rMyMy –   davidpauljunior  May 14 '13 at 4:06 1   Found it: stop wrapping  customModal as a jQuery object. Pass it as a string instead. e.g. customModal = '<div class=...' When you turned it into a jQuery object, it still exists after you take it out of the DOM and continues to receive amendments. –  thefrontender May 14 '13 at 4:22  1   Updated JSFIddle jsfiddle.net/thefrontender/rMyMy/3 Wrapping the markup in jQuery turned it into a DOM fragment assigned to the customModal variable. Calling  remove pulled the elements out of the DOM but the amended DOM Fragment continued to exist in the variable customModal which would get amended to the DOM again the next time around, and it's changed contents persisted. –  thefrontender May 14 '13 at 4:33 show 1 more comment Not the answer you're looking for? Browse other questions tagged  jquery   twitter­bootstrap  or ask your own question.