$(document).on("click",".a",function(){ if($(this).next(".b").css("display") == 'block'){ $(this).next(".b").css("display","none"); }else{ $(this).next(".b").css("display","block"); } }) $(document).on("click",".b li",function(){ $(this).parents(".b").prev(".a").html($(this).html()); $(this).parents(".b").css("display","none"); })