Changing font-family on JS : can't set property of undefined
I seem to have a problem when trying to change font on click of a button with JS. Here is the function:
var fontFamily = 'papyrus'
function changeFont(fontFamily){
document.getElementsByClassName(".forma, .descrip").style.fontFamily
};
Here is my html line for the button that I use:
<input type="button" value="Mode Psychédélique"
onclick="chBackcolor('magenta'), changeColor('blue'),
changeHeadingColor('green'), changefont('papyrus')"> `
I get the error "Cannot set property of undefined", but I don't understand why since I put the variable.
Any thoughts?
BIG EDIT (sorry for that, former commenters)
javascript button onclick undefined fontfamily
|
show 1 more comment
I seem to have a problem when trying to change font on click of a button with JS. Here is the function:
var fontFamily = 'papyrus'
function changeFont(fontFamily){
document.getElementsByClassName(".forma, .descrip").style.fontFamily
};
Here is my html line for the button that I use:
<input type="button" value="Mode Psychédélique"
onclick="chBackcolor('magenta'), changeColor('blue'),
changeHeadingColor('green'), changefont('papyrus')"> `
I get the error "Cannot set property of undefined", but I don't understand why since I put the variable.
Any thoughts?
BIG EDIT (sorry for that, former commenters)
javascript button onclick undefined fontfamily
oDomElement.style.fontFamily = papyrus
i see a type here
– Code Maniac
Dec 28 '18 at 16:24
what do you mean @CodeManiac ?
– Zalachenka
Dec 28 '18 at 16:30
What isoDomElement
?
– Code Maniac
Dec 28 '18 at 16:32
Oh yes sorry @CodeManiac I see what you mean. I corrected it but still nothing
– Zalachenka
Dec 28 '18 at 16:44
Do the other 3 methods work for you (those which change color)? If you changedoDomElement
toele
and your code still doesn't work, please edit your post accordingly. Why you calcmatches
and don't use it? More importantly, have you tried changing font forh2
– the elements for which you changed color successfully?
– YakovL
Dec 28 '18 at 20:06
|
show 1 more comment
I seem to have a problem when trying to change font on click of a button with JS. Here is the function:
var fontFamily = 'papyrus'
function changeFont(fontFamily){
document.getElementsByClassName(".forma, .descrip").style.fontFamily
};
Here is my html line for the button that I use:
<input type="button" value="Mode Psychédélique"
onclick="chBackcolor('magenta'), changeColor('blue'),
changeHeadingColor('green'), changefont('papyrus')"> `
I get the error "Cannot set property of undefined", but I don't understand why since I put the variable.
Any thoughts?
BIG EDIT (sorry for that, former commenters)
javascript button onclick undefined fontfamily
I seem to have a problem when trying to change font on click of a button with JS. Here is the function:
var fontFamily = 'papyrus'
function changeFont(fontFamily){
document.getElementsByClassName(".forma, .descrip").style.fontFamily
};
Here is my html line for the button that I use:
<input type="button" value="Mode Psychédélique"
onclick="chBackcolor('magenta'), changeColor('blue'),
changeHeadingColor('green'), changefont('papyrus')"> `
I get the error "Cannot set property of undefined", but I don't understand why since I put the variable.
Any thoughts?
BIG EDIT (sorry for that, former commenters)
javascript button onclick undefined fontfamily
javascript button onclick undefined fontfamily
edited Jan 9 at 17:01
Zalachenka
asked Dec 28 '18 at 16:17
ZalachenkaZalachenka
163
163
oDomElement.style.fontFamily = papyrus
i see a type here
– Code Maniac
Dec 28 '18 at 16:24
what do you mean @CodeManiac ?
– Zalachenka
Dec 28 '18 at 16:30
What isoDomElement
?
– Code Maniac
Dec 28 '18 at 16:32
Oh yes sorry @CodeManiac I see what you mean. I corrected it but still nothing
– Zalachenka
Dec 28 '18 at 16:44
Do the other 3 methods work for you (those which change color)? If you changedoDomElement
toele
and your code still doesn't work, please edit your post accordingly. Why you calcmatches
and don't use it? More importantly, have you tried changing font forh2
– the elements for which you changed color successfully?
– YakovL
Dec 28 '18 at 20:06
|
show 1 more comment
oDomElement.style.fontFamily = papyrus
i see a type here
– Code Maniac
Dec 28 '18 at 16:24
what do you mean @CodeManiac ?
– Zalachenka
Dec 28 '18 at 16:30
What isoDomElement
?
– Code Maniac
Dec 28 '18 at 16:32
Oh yes sorry @CodeManiac I see what you mean. I corrected it but still nothing
– Zalachenka
Dec 28 '18 at 16:44
Do the other 3 methods work for you (those which change color)? If you changedoDomElement
toele
and your code still doesn't work, please edit your post accordingly. Why you calcmatches
and don't use it? More importantly, have you tried changing font forh2
– the elements for which you changed color successfully?
– YakovL
Dec 28 '18 at 20:06
oDomElement.style.fontFamily = papyrus
i see a type here– Code Maniac
Dec 28 '18 at 16:24
oDomElement.style.fontFamily = papyrus
i see a type here– Code Maniac
Dec 28 '18 at 16:24
what do you mean @CodeManiac ?
– Zalachenka
Dec 28 '18 at 16:30
what do you mean @CodeManiac ?
– Zalachenka
Dec 28 '18 at 16:30
What is
oDomElement
?– Code Maniac
Dec 28 '18 at 16:32
What is
oDomElement
?– Code Maniac
Dec 28 '18 at 16:32
Oh yes sorry @CodeManiac I see what you mean. I corrected it but still nothing
– Zalachenka
Dec 28 '18 at 16:44
Oh yes sorry @CodeManiac I see what you mean. I corrected it but still nothing
– Zalachenka
Dec 28 '18 at 16:44
Do the other 3 methods work for you (those which change color)? If you changed
oDomElement
to ele
and your code still doesn't work, please edit your post accordingly. Why you calc matches
and don't use it? More importantly, have you tried changing font for h2
– the elements for which you changed color successfully?– YakovL
Dec 28 '18 at 20:06
Do the other 3 methods work for you (those which change color)? If you changed
oDomElement
to ele
and your code still doesn't work, please edit your post accordingly. Why you calc matches
and don't use it? More importantly, have you tried changing font for h2
– the elements for which you changed color successfully?– YakovL
Dec 28 '18 at 20:06
|
show 1 more comment
1 Answer
1
active
oldest
votes
First, it seems like in your code
ele.style.fontFamily = papyrus
- No argument for papyrus
Unless you forgot to add "" quotes, there is no declared variable for papyrus
- Add type of font
This includes cursive, sans-serif, etc.
Try using this link if it helps: W3Schools fontFamily JS attribute
1
You should avoid to like against w3school, they used to have many errors and inaccuracies. While they got better after many complains they still have many flaws and incomplete informations mdn font-family is a more complete reference.
– t.niese
Dec 29 '18 at 16:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f53961340%2fchanging-font-family-on-js-cant-set-property-of-undefined%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First, it seems like in your code
ele.style.fontFamily = papyrus
- No argument for papyrus
Unless you forgot to add "" quotes, there is no declared variable for papyrus
- Add type of font
This includes cursive, sans-serif, etc.
Try using this link if it helps: W3Schools fontFamily JS attribute
1
You should avoid to like against w3school, they used to have many errors and inaccuracies. While they got better after many complains they still have many flaws and incomplete informations mdn font-family is a more complete reference.
– t.niese
Dec 29 '18 at 16:06
add a comment |
First, it seems like in your code
ele.style.fontFamily = papyrus
- No argument for papyrus
Unless you forgot to add "" quotes, there is no declared variable for papyrus
- Add type of font
This includes cursive, sans-serif, etc.
Try using this link if it helps: W3Schools fontFamily JS attribute
1
You should avoid to like against w3school, they used to have many errors and inaccuracies. While they got better after many complains they still have many flaws and incomplete informations mdn font-family is a more complete reference.
– t.niese
Dec 29 '18 at 16:06
add a comment |
First, it seems like in your code
ele.style.fontFamily = papyrus
- No argument for papyrus
Unless you forgot to add "" quotes, there is no declared variable for papyrus
- Add type of font
This includes cursive, sans-serif, etc.
Try using this link if it helps: W3Schools fontFamily JS attribute
First, it seems like in your code
ele.style.fontFamily = papyrus
- No argument for papyrus
Unless you forgot to add "" quotes, there is no declared variable for papyrus
- Add type of font
This includes cursive, sans-serif, etc.
Try using this link if it helps: W3Schools fontFamily JS attribute
answered Dec 29 '18 at 15:57
LeoDog896LeoDog896
12218
12218
1
You should avoid to like against w3school, they used to have many errors and inaccuracies. While they got better after many complains they still have many flaws and incomplete informations mdn font-family is a more complete reference.
– t.niese
Dec 29 '18 at 16:06
add a comment |
1
You should avoid to like against w3school, they used to have many errors and inaccuracies. While they got better after many complains they still have many flaws and incomplete informations mdn font-family is a more complete reference.
– t.niese
Dec 29 '18 at 16:06
1
1
You should avoid to like against w3school, they used to have many errors and inaccuracies. While they got better after many complains they still have many flaws and incomplete informations mdn font-family is a more complete reference.
– t.niese
Dec 29 '18 at 16:06
You should avoid to like against w3school, they used to have many errors and inaccuracies. While they got better after many complains they still have many flaws and incomplete informations mdn font-family is a more complete reference.
– t.niese
Dec 29 '18 at 16:06
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.
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%2f53961340%2fchanging-font-family-on-js-cant-set-property-of-undefined%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
oDomElement.style.fontFamily = papyrus
i see a type here– Code Maniac
Dec 28 '18 at 16:24
what do you mean @CodeManiac ?
– Zalachenka
Dec 28 '18 at 16:30
What is
oDomElement
?– Code Maniac
Dec 28 '18 at 16:32
Oh yes sorry @CodeManiac I see what you mean. I corrected it but still nothing
– Zalachenka
Dec 28 '18 at 16:44
Do the other 3 methods work for you (those which change color)? If you changed
oDomElement
toele
and your code still doesn't work, please edit your post accordingly. Why you calcmatches
and don't use it? More importantly, have you tried changing font forh2
– the elements for which you changed color successfully?– YakovL
Dec 28 '18 at 20:06