jquery - Checkbox is not selected when click on the button -


i'm trying checkbox before list items in listview. have page listview when click on "edit" button. listview adding checkboxes before list items when i'm clicking on checkbox's page automatically changes previous view (without checkboxes in listview).checkboxes not checked.where i'm doing wrong.

$('#fav').on('click', function() {     $("#favoriteslist").listview('refresh');     fromstorage();      $(document).on('click', '#empty', function() {         $("#favoriteslist").empty();         localstorage.clear();         $("#favoriteslist").listview('refresh');     });       $(document).on('click', '#edit', function() {         fromgetstorage();     }); });  function fromgetstorage() {     $("#favoriteslist").empty();     $(".ui-listview-filter").remove();     $("#favoriteslist").append('<input type="checkbox" name="all" id="select" />select all</br>');     (var = 0; < localstorage.length; i++) {         var url = localstorage.key(i);         var demo = localstorage.getitem(url);         $("#favoriteslist").append('<li><div><input type="checkbox" name="check" id="check">&nbsp;<a href="' + url + '" style="text-decoration:none;color:black">' + demo + '</a></div></li>').attr('url', url);         $("#favoriteslist").listview('refresh');         $('#select').click(function() {             if ($("#select").is(':checked')) {                 $("#check").prop("checked", true);             }             else {                 $("#check").prop("checked", false);             }              $("#favoriteslist").listview('refresh'); } 

as thirumalai said, providing jsfiddle lot.

i think problem can event bubbling in combination how jquery mobile works. jquery mobile processes listview , when finds <a> inside, automatically considers "link part" of item. when click on checkbox, apart checkbox being selected, click handler on higher level called well.

i try assing click handler checkbox , stop bubbling of event (http://api.jquery.com/event.stoppropagation/) not bubble higher level , not open link.

$("#check").click(function(event){     event.stoppropagation(); }); 

if don't need stick code, suggest constructing html similar way in post:

checkbox in listview jquery mobile

there jsfiddles well.

good luck.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -