Remove tag around a text node using javascript

前端 未结 8 1944
夕颜
夕颜 2021-02-06 14:12

If I have some HTML that looks like this:

This is some text that is being written with a high
8条回答
  •  日久生厌
    2021-02-06 15:06

    it would be much easier to just change the class of the span than to actually remove it. You can use pure javascript:

    document.getElementById("span id").className="";
    

    Or jquery's toggleClass function:

     $("element").toggleClass("highlight");
    

    Also, best practices say that you shouldn't use class names that imply a style, like highlight. Try "emphasized" instead. :D

提交回复
热议问题