How to get the body tag

$("body") .keydown (function () {

         if (event.keyCode == "13") {//keyCode=13
             document.getElementById("btnSumit").click();
         }
     });

the $("body") of this line of code is replaced with native document.body.keydown (function () {

         if (event.keyCode == "13") {//keyCode=13
             document.getElementById("btnSumit").click();
         }
     });

Why did you alarm that document.body is not a function


the first error report is Uncaught TypeError: document.body.keydown is not a function
document.body .keydown is not a function, not document.body

clipboard.png

secondly, keydown () is an instance method of a jQuery object, not a method on an dom instance. And to be honest, if the jQuery event binding specification is a little bit, it should be written as

.
$("body").on("keydown",function(e){
    //
})

so
we should write

document.querySelector("body").addEventListener("keydown",function(e){
    //
})

in order to have a chance to unbind later, it is best to give function a separate reference rather than an anonymous function


document.body.onkeydown = function(){
   if (event.keyCode == "13") {//keyCode=13
       document.getElementById('btnSumit').click();
   }
}

Native js writing directly requires the on prefix. onkeydown , onclick

if it's addEventListener , you don't need on prefix

.
document.body.onkeydown = function(){
   if (event.keyCode == "13") {//keyCode=13
       document.getElementById('btnSumit').onclick();
   }
}

------

document.body.addEventListener("keydown",function(){
   if (event.keyCode == "13") {//keyCode=13
       document.getElementById('btnSumit').onclick();
   }
},false)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e94f46-472d7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e94f46-472d7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?