var blk_have ='<div class="sw-off"></div>'; $('#blk').prepend(blk_have); $(document).on('click', '.sw-off', function(){ $(this).toggleClass('sw-on'); });