admin管理员组文章数量:1334290
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 hard code the value in case the stylesheet changes. I would like to use the default color used on the page.
Is resetting the color like this fine, or is there a better way to do this?
$('#theinput').css('color', '');
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 hard code the value in case the stylesheet changes. I would like to use the default color used on the page.
Is resetting the color like this fine, or is there a better way to do this?
$('#theinput').css('color', '');
Share
Improve this question
edited Dec 8, 2016 at 18:24
cweston
asked Mar 23, 2010 at 14:05
cwestoncweston
11.6k21 gold badges85 silver badges107 bronze badges
1
- If anyone manage to do that in a userscript for google doc... – JinSnow Commented Jul 15, 2021 at 9:09
3 Answers
Reset to default 28There's no better way. It's the standard way.
Basically, there's no way to delete a CSS attribute from the style property of DOM elements. So all you can do is set the attribute value to empty and let CSS do its job of reverting back to the stylesheet.
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.
Fine, but you have to specify the color inside quote and id of the input on what color should change.
This will work :)
$("#InputIdName").css('color', '#979797');
本文标签: Reset element color to default stylesheet color (jQueryJavascript)Stack Overflow
版权声明:本文标题:Reset element color to default stylesheet color (jQuery, JavaScript) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1737492419a1992591.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论