user3219243
user3219243

Reputation: 81

Event attached to button JQUERY

HTML Code:

<div class="row">
        <div class="col-sm-1 col-md-9"></div>
        <div class="col-sm-10 col-md-3">
            <div class="login-form">
                <form role="form" method="post">
                    <div class="form-group">
                        <label for="nick">Nick:</label>
                        <input class="form-control" type="text" id="nick-log" />
                        <span></span>
                    </div>
                    <div class="form-group">
                        <label for="password">Hasło</label>
                        <input class="form-control" type="password-log" id="password" />
                        <span></span>
                    </div>
                    <div class="checkbox">
                        <label><input type="checkbox" class="btn btn-default">Pamiętaj mnie</label>
                    </div>
                    <button id="login-button" class="btn btn-success" type="button">Zaloguj się</button>
                </form>
            </div>
        </div>
        <div class="col-sm-1"></div>

JS Code:

    $(function() {
        var checkLogForm=function(){
            alert('anything');
        };

        $('#login-button').on("click", fn)
    });

I don't know why but I can't attach any event to element #login-button. It works even with other elements in form. I've tried also with bind() function but it still doesn't work. Please help!

Upvotes: 1

Views: 66

Answers (4)

Mushahid Khan
Mushahid Khan

Reputation: 2834

   always  Use **ON()** instead of **click()**

enter link description here Check this https://jsfiddle.net/ncsr4tgh/1/ its working.....

Upvotes: 1

Vikash Kesarwani
Vikash Kesarwani

Reputation: 850

in $('#login-button').on("click", fn), fn is name of the callback function which will be called when an click event occurs on the button, which in your case is checkLogForm.

Upvotes: 0

Akash Chavda
Akash Chavda

Reputation: 1227

you can change your html

<button id="login-button" class="btn btn-success">Zaloguj się</button>

instead of

<button id="login-button" class="btn btn-success" type="button">Zaloguj się</button>

and change your js

$(document).on('click', '#login-button', function() {
     alert('anything');
});

I'm not sure but i think it's helpful to you.

Upvotes: 0

Zoran P.
Zoran P.

Reputation: 880

ChecklogForm or any other function needs to be either outaide of document ready function or both ChecklogForm and binding code need to be inside the same document ready function.

Upvotes: 0

Related Questions