how can i add a success funcion?
<p>I would like to add a success and fail function but how can i do it? I have this code bellow:</p>

<pre><code>    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
    })

&lt;span id="target"&gt;&lt;/span&gt;//here will appear the value passed before
</code></pre>

<p>How could I add a function that tells me if everything was ok or wrong? Ive been trying but i cannot solve this
Example of how id like that works</p>

<pre><code>    class ={};

    class.hey = function(values)
    {
      document.getElementById(values.id).innerHTML = values.Val ;

    return class;
    }



    class.hey({
    id:"objetive",//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");
   }
    })

&lt;span id="target"&gt;&lt;/span&gt;//here will appear the value passed before
</code></pre>
