removing html element styles via javascript

前端 未结 8 568
没有蜡笔的小新
没有蜡笔的小新 2020-12-07 20:34

I\'m trying to replace an element\'s inline style tag value. The current element looks like this:

`

        
相关标签:
8条回答
  • 2020-12-07 20:47

    Use

    particular_node.classList.remove("<name-of-class>")

    For native javascript

    0 讨论(0)
  • 2020-12-07 20:47

    Completly removing style, not only set to NULL

    document.getElementById("id").removeAttribute("style")
    
    0 讨论(0)
  • 2020-12-07 20:56

    In JavaScript:

    document.getElementById("id").style.display = null;
    

    In jQuery:

    $("#id").css('display',null);
    
    0 讨论(0)
  • 2020-12-07 20:56

    Remove removeProperty

    var el=document.getElementById("id");
    
    
    el.style.removeProperty('display')
    
    console.log("display removed"+el.style["display"])
    
    console.log("color "+el.style["color"])
    <div id="id" style="display:block;color:red">s</div>

    0 讨论(0)
  • 2020-12-07 20:58

    The class attribute can contain multiple styles, so you could specify it as

    <tr class="row-even highlight">
    

    and do string manipulation to remove 'highlight' from element.className

    element.className=element.className.replace('hightlight','');
    

    Using jQuery would make this simpler as you have the methods

    $("#id").addClass("highlight");
    $("#id").removeClass("hightlight");
    

    that would enable you to toggle highlighting easily

    0 讨论(0)
  • 2020-12-07 21:00

    In jQuery, you can use

    $(".className").attr("style","");
    
    0 讨论(0)
提交回复
热议问题