W moim kodu, widzę to:document.getelementbyId zwróci wartość null, jeśli element nie jest zdefiniowany?
if (document.getElementById('xx') !=null) {
//do stuff
}
jeśli xx
element nie jest zdefiniowany, to ocenia się prawda czy fałsz?
powinienem napisać:
if (document.getElementById('xx'))
być bezpieczne?
... 'null, jeśli element o podanym ID nie znajduje się w dokumencie' ([mdn] (https://developer.mozilla.org/en-US/docs/DOM/document.getElementById)) – raina77ow
'document.getElementById ('xx')' zwraca 'undefined' –
@KhanhTran W rzeczywistości zwraca' null'. Przetestuj go w konsoli. –