+ 4
Error: cannot set property 'onclick' on null
when I turn that Code by Netbeans ,it is working fine. whats is the problem in sololearn?
7 Respuestas
+ 7
change your code to this
/*
Show Password with Pure JavaScript
*/
function start(){
var myInput = document.getElementById('myInput'),
    myBtn = document.getElementById('myBtn');
myBtn.onclick = function () {
    'use strict';
    if (this.textContent === "Show Password") {
        myInput.setAttribute('type', 'text');
        this.textContent = "Hide Password";
    } else {
        myInput.setAttribute('type', 'password');
        this.textContent = "Show Password";
    }
};
}
window.onload=start;
wrap it up in a function and call it once the HTML is fully loaded
+ 6
/*
Change Image Evert X Seconds
*/
function start(){
var myImge = document.getElementById('myImg'),
    arrImgs = [
        "https://placehold.it/100/#fff",
        "https://placehold.it/100/#f00",
        "https://placehold.it/100/#00f",
        "https://placehold.it/100/#ddd"
        ];
function changeImg(myImge, arrImgs) {
    'use strict';
    setInterval(function () {
        var randomImg = Math.floor(Math.random() * arrImgs.length);
        myImge.src = arrImgs[randomImg];
    }, 1000);
};
changeImg(myImge, arrImgs);
}
window.onload = start;
same problem, javascript attemp to access elements in the HTML before it is loaded completely
so wrap everything with a function which will be called after HTML is loaded
and call the function once inside
+ 5
no probs :)
+ 1
it's working..thanx alot Burey.
+ 1
Buery..Could you please check error of :cannot set property 'src' of null..? what's the problem of 'src'
+ 1
thank you Burey, i got the error where it came from..thanks 4 your help
+ 1
window.onload=start();



