Is it possible to incorporate success and fail functions into the following code? I'm struggling with how to do it. Here is the code snippet:
class ={};
class.hey = function(values)
{
document.getElementById(values.id).innerHTML = values.Val ;
return class;
}
class.hey({
id:"target",
Val: "hello world",//this wil work and will display that value in the span tag
})
<span id="target"></span>//here will appear the value passed before
I'm having trouble figuring out how to add a function that can indicate success or failure. Here's an example of how I would like it to work:
class ={};
class.hey = function(values)
{
document.getElementById(values.id).innerHTML = values.Val ;
return class;
}
class.hey({
id:"objective", //the element does not exist
Val: "hello world", //this wil work and will display that value in the span tag
success:function(msg)
{
alert("ok!")
},
error:function(msg){
alert("wrong");
}
})
<span id="target"></span>//here will appear the value passed before