Maxbester
Maxbester

Reputation: 2533

Fire checkbox event with jQuery Mobile

I am using jQuery 1.8.3 and jQuery Mobile 1.2.0.

I am trying to implement the vertically grouped checkboxes.

I need to detect changes on the checkboxes. An example is available here.

However, it doesn't work on my page (which I don't give because it contains too many dependencies but the code is the same).

Basically, when I click a checkbox, the following message should be displayed in the console:

INPUT
module1
-----

Whereas in my page I've got:

FIELDSET
moduleListTitle
-----
DIV
moduleContainer
-----
DIV
(an empty string)
-----

I've spent hours trying to find why the event is not fired correctly.

Has anyone already faced this problem?

Upvotes: 1

Views: 2009

Answers (1)

Omar
Omar

Reputation: 31732

After testing the code live - not on JSfiddle - I have reached the below solution.

Since the items are added dynamically, you should bind the event to $(document) and the handler to 'input:checkbox.module'.

Here is the code, I hope it solves your problem.

$(document).on('change','input:checkbox.module', function(){
 console.log(this.tagName);
 console.log(this.id);
 console.log("-----");
});

trigger.('refresh') is not required here.

Upvotes: 2

Related Questions