2021-02-25

Why can't I refer to items created with js?

Items are displayed in the index, but their classes (sass and script) do not work because they refer to these newly created items.

HTML

<body>
    <section>
        <div class="container">
            <div class="center_container">
                <div class="title">
                    <h1></h1>
                </div>
                <div class="login_buttons">
                    <div class="log_in">
                        <input type="button" class="login_button" value="Log in">
                    </div>
                    <div class="sing_up">
                        <input type="button" class="register_button" value="Sing up">
                    </div>
                </div>
            </div>
        </div>
    </section>

JS/JQ

$('.login_button').click(
    function() {
        var loginArea = '<div class="real_login"><form><input id="username" type="text" placeholder="Username..."><input id="password" placeholder="Password..."><input type="button" class="loginButton" value="Sing In"></form><div>'

        $('.login_buttons').remove()     
        $('.center_container').append(loginArea)
    }
)

$('.loginButton').click(
    function (){
        alert("button works")
        var usernameArea = document.getElementById("username").value
        var passwordArea = document.getElementById("password").value
    
        for ( var i = 0; i < objUsers.length; i++ ) {
            if( usernameArea == objUsers[i].username && passwordArea == objUsers[i].password ){
                console.log("Welcome " + usernameArea)
                return location.href = 'index.html'
            } else {
                console.log("Incorrect login or password.")
            }
        }
    }
)


from Recent Questions - Stack Overflow https://ift.tt/3uwh18A
https://ift.tt/eA8V8J

No comments:

Post a Comment