$(document).ready(function() { var dvjQuery = null; $('#btnAdd').attr('disabled','disabled'); $("#dvjQuery").hover(function() { $(this).addClass('highlight'); }, function() { $(this).removeClass('highlight'); }); $('#btnRemove').click(function() { dvjQuery = $("#dvjQuery").remove(); $(this).attr('disabled','disabled'); $('#btnAdd').removeAttr('disabled'); }); $('#btnAdd').click(function() { $("#dvParent").html(dvjQuery); $(this).attr('disabled','disabled'); $('#btnRemove').removeAttr('disabled'); }); });
<form> <div id="dvParent"> <div id="dvjQuery">jQuery By Example is a good blog to learn jQuery. </div> </div> <br/><br/> <input type='button' id='btnRemove' Value=' Remove Div ' /> <input type='button' id='btnAdd' Value=' Add Div ' /> <br/><br/> </form>