jQuery trigger('click') not working with Jasmine-jquery

This is my test code:

describe("Login", function(){

    it("should enable the button when checking 'remember password'", function(){

And this is my production code:


    $('#remember').click(function(e) {


This is not working, the production code never gets called. I have put alerts before and after the trigger event and after the trigger the checkbox is checked, but the .click function does not get called.

Any thoughts on why is this happening?



Without seeing the rest of the code, I'm assuming the "login-fixture.html" contains the "#remember" checkbox. If so, it's loading after the DOM loads. Meaning that the 'click' event you want assigned will only apply to previously loaded elements. The jQuery on() event will assign any event you want to newly loaded elements. You might want to try adding a on() event to that id. Something like:

    $('#remember').on('click', function(){

Hope that helps.

See: http://api.jquery.com/on/


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.