JavaScript Run javascript function when replaceWith finishes loading javascript function when page loads,javascript function when button clicked,

Try

$(document).ready(function() {
  var body = $("body");
  $("#myDiv").click(function(e) {
    var html =  $("<div>Hello World!!!</div>");
    $("#myDiv").replaceWith(html)
      .promise().done(function(elem) {
        if (body.find(html).is("*") 
            && !body.find(elem).is("*")) {
               alert("done");
        }
      });    
  });
});

$(document).ready(function() {
  var body = $("body");
  $("#myDiv").click(function(e) {
    var html = $("<img src=http://lorempixel.com/output/cats-q-c-1920-1920-2.jpg />");
        
        // $("<div>Hello World!!!</div>"); 

       
    $("#myDiv").replaceWith(html)
      .promise().done(function(elem) {
        if (body.find(html).is("*") 
            && !body.find(elem).is("*")) {
               alert("done");
        }
      });

  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myDiv">Hello!</div>
Answer:1

I would try getting the value of what you're replacing - then check if it exists after the replacement - then you can alert its complete.

fiddle: http://jsfiddle.net/eavxkc3f/

jquery:

$(document).ready(function (){
  $(".myDiv").click(function () {

      var currentItem = $(".myDiv").html();
      var replacer = "<div>Hello World!!!</div>";

      $(".myDiv").replaceWith("<div>Hello World!!!</div>");

      if($(".myDiv").html != currentItem){
          alert("Done.");
      }

  });
});
Answer:2

I have a problem. When I first time press on the link div show's then when I press on document it's disappear. When I press second time on link div appears and suddenly disappears. What's wrong? $(...

I have a problem. When I first time press on the link div show's then when I press on document it's disappear. When I press second time on link div appears and suddenly disappears. What's wrong? $(...

  1. jquery show hide div
  2. jquery show hide toggle
  3. jquery show hide not working
  4. jquery show hide class
  5. jquery show hide boolean
  6. jquery show hide div by id
  7. jquery show hide span
  8. jquery show hide password
  9. jquery show hide on click
  10. jquery show hide label
  11. jquery show hide fade
  12. jquery show hide table row
  13. jquery show hide css
  14. jquery show hide based on class
  15. jquery show hide table
  16. jquery show hide button by id
  17. jquery show hide display none
  18. jquery show hide modal
  19. jquery show hide on load
  20. jquery show hide checkbox

I've been going crazy trying to figure this one out. I've seen plenty of obfuscated and tough-to-implement examples of filling a computed observable in Knockout when an async call has finished, but I ...

I've been going crazy trying to figure this one out. I've seen plenty of obfuscated and tough-to-implement examples of filling a computed observable in Knockout when an async call has finished, but I ...

I'm trying to make a .jsp where, by clicking a button, the page opens a modal dialog with some stuff. I'm also using jQuery. I'm new to this, so, to test if jQuery was working, I first tried a kind of ...

I'm trying to make a .jsp where, by clicking a button, the page opens a modal dialog with some stuff. I'm also using jQuery. I'm new to this, so, to test if jQuery was working, I first tried a kind of ...

I'm learning Angular but having troubles to understand a point. I want to get data from my server. I used this code (from angular's doc) : this.myFunction = new function() { var uri = this....

I'm learning Angular but having troubles to understand a point. I want to get data from my server. I used this code (from angular's doc) : this.myFunction = new function() { var uri = this....

  1. understanding angular momentum
  2. understanding angular.json
  3. understanding angular modules
  4. understanding angularjs
  5. understanding angular observables
  6. understanding angular routing
  7. understanding angular 8
  8. understanding angular lifecycle hooks
  9. understanding angular dependency injection
  10. understanding angular project structure
  11. understanding angular components
  12. understanding angular directives
  13. understanding angular error messages
  14. understanding angular services
  15. understanding angular change detection
  16. understanding angularjs digest life-cycle
  17. understanding angular architecture
  18. understanding angular source code
  19. understanding angular reactive forms