Replace img with div jQuery - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:replaceWith

Description

Replace img with div jQuery

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*  ww  w  . ja v  a  2  s.co m*/
$(".myImage").replaceWith('<div>hello</div>');
    });

      </script> 
 </head> 
 <body> 
  <div> 
   <img class="myImage" src="http://www.java2s.com/style/demo/Safari.png"> 
   <div>
     Don't clear me 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials