Difference between getElementById and jquery $('#smth')

前端 未结 4 1336
猫巷女王i
猫巷女王i 2020-12-29 21:19

What\'s the difference between classic Javascript code:

document.getElementById(\'theID\')

and the jQuery version:

$(\'#the         


        
4条回答
  •  醉梦人生
    2020-12-29 21:59

    Not quite : If an element with that id is not existing on the page $("#id") will not work and the script will stop document.getElementById("id") will return null

提交回复
热议问题