有没有办法隐藏html标签内的角色?

时间:2018-03-14 17:27:15

标签: jquery html css

class="WooZone-free-shipping"的范围标记内部有&个字符。我出于某种原因无法将其从代码中删除,但我必须将其隐藏在此页面上。 我试着用以下jQuery做到这一点:

jQuery('.WooZone-free-shipping').html(jQuery('.WooZone-free-shipping').html().replace("&",""));

并使用此css:

span.WooZone-free-shipping:nth-child(1) {
    display: none;
}

但这两种方法都不起作用。

enter image description here

1 个答案:

答案 0 :(得分:1)

html()会将&转换为amp。您需要在替换

时使用text

console.log("TEXT - "+jQuery('.WooZone-free-shipping').text());
console.log("HTML - "+jQuery('.WooZone-free-shipping').html());
jQuery('.WooZone-free-shipping').html(jQuery('.WooZone-free-shipping').text().replace("&",""));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="WooZone-free-shipping">ABC&amp;D</div>