javascript - Function for setting text of an element -


// function setting text of element:  function settext(elementid, message)   {      'use strict';               if ( (typeof elementid == 'string')&& (typeof message == 'string') )      {        var output = $(elementid);      if (output.textcontent !== undefined)        {        output.textcontent = $(elementid).string;        }        else        {        output.innertext =$(elementid).string ;      }            } // end of main if.  } // end of settext() function.

i need code, need define function name settext() function shown below, when run code in js bin page shows code won't run, couldn't find error is. can give me hint?

your type checking message unnecessary, in case want keep it:

function settext(elementid, message){      if((typeof elementid == 'string') && (typeof message == 'string')){           document.getelementbyid(elementid).innerhtml = message;      }  }    settext("foo", "1")  settext("foobar", "2")  settext("bar", "3")  settext("barfoo", "4")
<p id="foo"></p>  <p id="foobar"></p>  <p id="bar"></p>  <p id="barfoo"></p>


Popular posts from this blog