Reset element color to default stylesheet color (jQuery, JavaScript)

前端 未结 3 919
囚心锁ツ
囚心锁ツ 2021-02-18 13:35

I need to be able to reset an input field back to its original color after it has been possibly changed via javascript to a different value. The problem is I do not want to har

3条回答
  •  盖世英雄少女心
    2021-02-18 14:36

    If you wanted to do it in plain JavaScript, you could do:

    document.getElementById('theinput').style.color = '';
    

    The only issue with this, or your jQuery method, is if the HTML has a style attribute that sets the color CSS property. If you wanted to preserve that, you’d have to store it on page load.

    But if it’s alright to assume there isn’t a style attribute, then you’re golden.

提交回复
热议问题