鼠标移入移出,获取当前元素

<style>
p{
    display: inline-block;
    width: 5rem;
    margin-bottom: 15px;
    margin-right: 10px;
    height: 1.875rem;
    text-align: center;
    line-height: 1.875rem;
    background: rgba(248,248,248,1);
    border: 1px solid rgba(221,221,221,1);
    font-size: 12px;
    font-family: MicrosoftYaHei;
    position: relative;
    color: rgba(51,51,51,1);
}
p img{
    width: 1rem;
    height: 1rem;
    position: absolute;
    top: -0.5rem;
    right: -0.5rem;
    display: none;
}
</style>
<body>
<p class="msg">
    市场化
    <img src="../img/close2.png" alt="">
</p>
<p class="msg">
    权益类
    <img src="../img/close2.png" alt="">
</p>
<script>
//鼠标移入移出
//第一种方法
    $(function(){
        $(msg).on({
            mouseover : function(){
                $(this).find('img').show();
          } ,
          mouseout : function(){
              $(this).find('img').hide();
          } 
        }) ;
    }) ; 
//第二种方法
    $(function(){
        $(msg).hover({
            function(){
                $(this).find('img').show();
          } ,
            function(){
                $(this).find('img').hide();
          } 
        }) ;
    }) ; 
//删除当前标签
    $(function(){
        $(this).parent().hide()
    })
</script>
</body>

鼠标移入,切换当前标签

$(this).wrap('<h1>')

标签切换回来

$(this).unwrap()
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容