methods in java script and calling multiple methods
up vote
-1
down vote
favorite
why can't i call both changeBackground() and toNormal() as method from custom
when i remove toNormal as a method and place it outside custom as a stand-alone function the code works but while in custom it does not
can an object hold more than one method
var custom =
{
changeBackground : function(){
var text = document.getElementById("para").style.backgroundColor ="red";
}
toNormal : function(){
var text = document.getElementById("para").style.backgroundColor ="";
}
}
this is some text
javascript
New contributor
Ronald Ubong Ekong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
-1
down vote
favorite
why can't i call both changeBackground() and toNormal() as method from custom
when i remove toNormal as a method and place it outside custom as a stand-alone function the code works but while in custom it does not
can an object hold more than one method
var custom =
{
changeBackground : function(){
var text = document.getElementById("para").style.backgroundColor ="red";
}
toNormal : function(){
var text = document.getElementById("para").style.backgroundColor ="";
}
}
this is some text
javascript
New contributor
Ronald Ubong Ekong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
Please format your code properly, you'll see, that a comma is missing.
– Teemu
yesterday
please also be more precise in your English text ... "as method from custom" - a custom what? banana, apple, function, object???
– quant
yesterday
Check this out. jsfiddle.net/knm2y8sp/2
– solooo7
yesterday
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
why can't i call both changeBackground() and toNormal() as method from custom
when i remove toNormal as a method and place it outside custom as a stand-alone function the code works but while in custom it does not
can an object hold more than one method
var custom =
{
changeBackground : function(){
var text = document.getElementById("para").style.backgroundColor ="red";
}
toNormal : function(){
var text = document.getElementById("para").style.backgroundColor ="";
}
}
this is some text
javascript
New contributor
Ronald Ubong Ekong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
why can't i call both changeBackground() and toNormal() as method from custom
when i remove toNormal as a method and place it outside custom as a stand-alone function the code works but while in custom it does not
can an object hold more than one method
var custom =
{
changeBackground : function(){
var text = document.getElementById("para").style.backgroundColor ="red";
}
toNormal : function(){
var text = document.getElementById("para").style.backgroundColor ="";
}
}
this is some text
javascript
javascript
New contributor
Ronald Ubong Ekong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ronald Ubong Ekong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ronald Ubong Ekong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked yesterday
Ronald Ubong Ekong
11
11
New contributor
Ronald Ubong Ekong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ronald Ubong Ekong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Ronald Ubong Ekong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
Please format your code properly, you'll see, that a comma is missing.
– Teemu
yesterday
please also be more precise in your English text ... "as method from custom" - a custom what? banana, apple, function, object???
– quant
yesterday
Check this out. jsfiddle.net/knm2y8sp/2
– solooo7
yesterday
add a comment |
2
Please format your code properly, you'll see, that a comma is missing.
– Teemu
yesterday
please also be more precise in your English text ... "as method from custom" - a custom what? banana, apple, function, object???
– quant
yesterday
Check this out. jsfiddle.net/knm2y8sp/2
– solooo7
yesterday
2
2
Please format your code properly, you'll see, that a comma is missing.
– Teemu
yesterday
Please format your code properly, you'll see, that a comma is missing.
– Teemu
yesterday
please also be more precise in your English text ... "as method from custom" - a custom what? banana, apple, function, object???
– quant
yesterday
please also be more precise in your English text ... "as method from custom" - a custom what? banana, apple, function, object???
– quant
yesterday
Check this out. jsfiddle.net/knm2y8sp/2
– solooo7
yesterday
Check this out. jsfiddle.net/knm2y8sp/2
– solooo7
yesterday
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
You forgot the , after your changeBackground function. A list of objects requires them to be seperated by a comma.
var custom = {
changeBackground: function() {
var text = document.getElementById("para").style.backgroundColor = "red";
}, //<-- this
toNormal: function() {
var text = document.getElementById("para").style.backgroundColor = "";
}
}
custom.changeBackground();
setTimeout(custom.toNormal, 1000);div {
width: 100px;
height: 100px;
}<div id="para"></div>add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
You forgot the , after your changeBackground function. A list of objects requires them to be seperated by a comma.
var custom = {
changeBackground: function() {
var text = document.getElementById("para").style.backgroundColor = "red";
}, //<-- this
toNormal: function() {
var text = document.getElementById("para").style.backgroundColor = "";
}
}
custom.changeBackground();
setTimeout(custom.toNormal, 1000);div {
width: 100px;
height: 100px;
}<div id="para"></div>add a comment |
up vote
2
down vote
You forgot the , after your changeBackground function. A list of objects requires them to be seperated by a comma.
var custom = {
changeBackground: function() {
var text = document.getElementById("para").style.backgroundColor = "red";
}, //<-- this
toNormal: function() {
var text = document.getElementById("para").style.backgroundColor = "";
}
}
custom.changeBackground();
setTimeout(custom.toNormal, 1000);div {
width: 100px;
height: 100px;
}<div id="para"></div>add a comment |
up vote
2
down vote
up vote
2
down vote
You forgot the , after your changeBackground function. A list of objects requires them to be seperated by a comma.
var custom = {
changeBackground: function() {
var text = document.getElementById("para").style.backgroundColor = "red";
}, //<-- this
toNormal: function() {
var text = document.getElementById("para").style.backgroundColor = "";
}
}
custom.changeBackground();
setTimeout(custom.toNormal, 1000);div {
width: 100px;
height: 100px;
}<div id="para"></div>You forgot the , after your changeBackground function. A list of objects requires them to be seperated by a comma.
var custom = {
changeBackground: function() {
var text = document.getElementById("para").style.backgroundColor = "red";
}, //<-- this
toNormal: function() {
var text = document.getElementById("para").style.backgroundColor = "";
}
}
custom.changeBackground();
setTimeout(custom.toNormal, 1000);div {
width: 100px;
height: 100px;
}<div id="para"></div>var custom = {
changeBackground: function() {
var text = document.getElementById("para").style.backgroundColor = "red";
}, //<-- this
toNormal: function() {
var text = document.getElementById("para").style.backgroundColor = "";
}
}
custom.changeBackground();
setTimeout(custom.toNormal, 1000);div {
width: 100px;
height: 100px;
}<div id="para"></div>var custom = {
changeBackground: function() {
var text = document.getElementById("para").style.backgroundColor = "red";
}, //<-- this
toNormal: function() {
var text = document.getElementById("para").style.backgroundColor = "";
}
}
custom.changeBackground();
setTimeout(custom.toNormal, 1000);div {
width: 100px;
height: 100px;
}<div id="para"></div>answered yesterday
kemicofa
7,47643476
7,47643476
add a comment |
add a comment |
Ronald Ubong Ekong is a new contributor. Be nice, and check out our Code of Conduct.
Ronald Ubong Ekong is a new contributor. Be nice, and check out our Code of Conduct.
Ronald Ubong Ekong is a new contributor. Be nice, and check out our Code of Conduct.
Ronald Ubong Ekong is a new contributor. Be nice, and check out our Code of Conduct.
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
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203396%2fmethods-in-java-script-and-calling-multiple-methods%23new-answer', 'question_page');
}
);
Post as a guest
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
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
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
2
Please format your code properly, you'll see, that a comma is missing.
– Teemu
yesterday
please also be more precise in your English text ... "as method from custom" - a custom what? banana, apple, function, object???
– quant
yesterday
Check this out. jsfiddle.net/knm2y8sp/2
– solooo7
yesterday