SoFunction
Updated on 2025-04-06

A brief discussion on the createElement event in javascript

createElement is the concept of using the W3C DOM object model to create child nodes, that is, child elements in HTML

Copy the codeThe code is as follows:

 <script>
   = function () {
   var input  = ('input');
   var button = ('input');
   ='text'; 
   = 'text';
   ='1';
   ='button';
='Add to add';
   = '40px';
   = '23px';
   (input);
   (button);
   = function(){
      var value = ;
      = value * 1 + 1;
   }
  }
 </script>

Note: value is actually a character. If you change =value*1+1; to =value+1; the result will appear 111111. It constantly adds 1 in the form of a character, so at this time the value*1 can convert the value value into Int type.

Summarize:

To ultimately solve the compatibility problem of the createElement method, you should still pay attention to judging the browser. For IE, you can use its unique method by passing in a legitimate HTML code string as a parameter for createElement. Non-IE browsers still use the standard method of W3C specification.