Why document.execCommand(''backColor'') does not work with css variable while foreColor does?
up vote
0
down vote
favorite
I need to execute document.execCommand('backColor')
command with css variable, but something goes wrong. No background style added at all. foreColor
works as expected and adds color style with the variable. I am doing this within Angular 7 environment.
function redBg() {
document.execCommand('styleWithCSS', true, null);
document.execCommand('backColor', false, 'var(--red)');
}
function redFg() {
document.execCommand('styleWithCSS', true, null);
document.execCommand('foreColor', false, 'var(--red)');
}
.content {
background: #ccc;
width: 100%;
}
.button {
font-size: 20px;
background: #f00;
user-select: none;
margin: 5px;
}
--red: red;
<div class="content" contentEditable="true">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div class="button" onmousedown="redBg()">Red bg</div>
<div class="button" onmousedown="redFg()">Red fg</div>
javascript html css execcommand css-variables
add a comment |
up vote
0
down vote
favorite
I need to execute document.execCommand('backColor')
command with css variable, but something goes wrong. No background style added at all. foreColor
works as expected and adds color style with the variable. I am doing this within Angular 7 environment.
function redBg() {
document.execCommand('styleWithCSS', true, null);
document.execCommand('backColor', false, 'var(--red)');
}
function redFg() {
document.execCommand('styleWithCSS', true, null);
document.execCommand('foreColor', false, 'var(--red)');
}
.content {
background: #ccc;
width: 100%;
}
.button {
font-size: 20px;
background: #f00;
user-select: none;
margin: 5px;
}
--red: red;
<div class="content" contentEditable="true">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div class="button" onmousedown="redBg()">Red bg</div>
<div class="button" onmousedown="redFg()">Red fg</div>
javascript html css execcommand css-variables
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to execute document.execCommand('backColor')
command with css variable, but something goes wrong. No background style added at all. foreColor
works as expected and adds color style with the variable. I am doing this within Angular 7 environment.
function redBg() {
document.execCommand('styleWithCSS', true, null);
document.execCommand('backColor', false, 'var(--red)');
}
function redFg() {
document.execCommand('styleWithCSS', true, null);
document.execCommand('foreColor', false, 'var(--red)');
}
.content {
background: #ccc;
width: 100%;
}
.button {
font-size: 20px;
background: #f00;
user-select: none;
margin: 5px;
}
--red: red;
<div class="content" contentEditable="true">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div class="button" onmousedown="redBg()">Red bg</div>
<div class="button" onmousedown="redFg()">Red fg</div>
javascript html css execcommand css-variables
I need to execute document.execCommand('backColor')
command with css variable, but something goes wrong. No background style added at all. foreColor
works as expected and adds color style with the variable. I am doing this within Angular 7 environment.
function redBg() {
document.execCommand('styleWithCSS', true, null);
document.execCommand('backColor', false, 'var(--red)');
}
function redFg() {
document.execCommand('styleWithCSS', true, null);
document.execCommand('foreColor', false, 'var(--red)');
}
.content {
background: #ccc;
width: 100%;
}
.button {
font-size: 20px;
background: #f00;
user-select: none;
margin: 5px;
}
--red: red;
<div class="content" contentEditable="true">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div class="button" onmousedown="redBg()">Red bg</div>
<div class="button" onmousedown="redFg()">Red fg</div>
function redBg() {
document.execCommand('styleWithCSS', true, null);
document.execCommand('backColor', false, 'var(--red)');
}
function redFg() {
document.execCommand('styleWithCSS', true, null);
document.execCommand('foreColor', false, 'var(--red)');
}
.content {
background: #ccc;
width: 100%;
}
.button {
font-size: 20px;
background: #f00;
user-select: none;
margin: 5px;
}
--red: red;
<div class="content" contentEditable="true">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div class="button" onmousedown="redBg()">Red bg</div>
<div class="button" onmousedown="redFg()">Red fg</div>
function redBg() {
document.execCommand('styleWithCSS', true, null);
document.execCommand('backColor', false, 'var(--red)');
}
function redFg() {
document.execCommand('styleWithCSS', true, null);
document.execCommand('foreColor', false, 'var(--red)');
}
.content {
background: #ccc;
width: 100%;
}
.button {
font-size: 20px;
background: #f00;
user-select: none;
margin: 5px;
}
--red: red;
<div class="content" contentEditable="true">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div class="button" onmousedown="redBg()">Red bg</div>
<div class="button" onmousedown="redFg()">Red fg</div>
javascript html css execcommand css-variables
javascript html css execcommand css-variables
asked Nov 19 at 22:20
vulp
399217
399217
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The value argument must be a CSS <color>
per:
This requires a value string to be passed in as a value
argument.
and specified per one of these methods:
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
Using a custom CSS property isn't a CSS <color>
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The value argument must be a CSS <color>
per:
This requires a value string to be passed in as a value
argument.
and specified per one of these methods:
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
Using a custom CSS property isn't a CSS <color>
add a comment |
up vote
1
down vote
accepted
The value argument must be a CSS <color>
per:
This requires a value string to be passed in as a value
argument.
and specified per one of these methods:
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
Using a custom CSS property isn't a CSS <color>
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The value argument must be a CSS <color>
per:
This requires a value string to be passed in as a value
argument.
and specified per one of these methods:
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
Using a custom CSS property isn't a CSS <color>
The value argument must be a CSS <color>
per:
This requires a value string to be passed in as a value
argument.
and specified per one of these methods:
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
Using a custom CSS property isn't a CSS <color>
answered Nov 19 at 22:47
Randy Casburn
3,9901218
3,9901218
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383478%2fwhy-document-execcommandbackcolor-does-not-work-with-css-variable-while-fo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown