<a> tag breaks style when unwrapped

时间:2018-03-26 19:45:03

标签: javascript html conditional

me again, i have this script so that when the button "quadrant_1" that is on another html page is clicked it changes the button color on the first html page, but also i want this to disable the a href link, for that i have this:

        var noLink = $('a')
 if(localStorage.getItem('quadrant_1', ) === 'clicked'){
    $("#btn-institucional").css({backgroundColor: "#d8d8d6"});
   $("#btn-institucional").unwrap({noLink});

   }

To remove the tag but the problem is that when th tag is removed it breaks all the row and buttons style

before tag is removed

After Tag was removed

这是按钮html

之一
<div class="number button col-lg-3 col-md-3 col-sm-12 col-xs-12" style="color:#ffffff; background-color:#003E8B; cursor: pointer; color: #ffffff;" id="btn-institucional">
            <a href="gobierno.html" >

            <p>1</p>

            <img src="icons/institucional.png" width= "50%">

            <p>Desarrollo Institucional para un Buen Gobierno</p>   


        </a></div>

非常感谢你的帮助,我真的不知道为什么会发生这种情况,如果我在div的引导类外面有div。

1 个答案:

答案 0 :(得分:0)

我认为样式中断是因为您尝试unwrap('a')删除了<div>

您可以尝试这样的事情:

 if(localStorage.getItem('quadrant_1', ) === 'clicked'){
   $("#btn-institucional").css({backgroundColor: "#d8d8d6"});
   $("#btn-institucional p").unwrap();
 }
相关问题