javascript - doesn't work .buttonset() on jQuery -


i have number of :checkbox elements initialized wordpress. set .buttonset() function #format not work... sample:http://jqueryui.com/button/#checkbox

html:

<div id="format">     <?php      $categories = get_categories();      foreach ($categories $category) { ?>      <input type="checkbox" name="check" value="<?php echo $category->cat_id; ?>">      <label><?php echo $category->cat_name;?></label><?php } ?> </div> 

js:

$('#format').buttonset(); $('input[type=checkbox]').removeclass('ui-helper-hidden-accessible');  $(':checkbox[name=check]').each(function( ){     var nameid = 'check'+ (i+1);     this.id = nameid;     $(this).next('label').prop('for', nameid);  }); 

all checkboxes has same name "check". try this:

<div id="format">     <?php      $i = 0;      $categories = get_categories();      foreach ($categories $category) { ?>      <input type="checkbox" name="check<?php echo $i ?>" value="<?php echo $category->cat_id; ?>">      <label><?php echo $category->cat_name;?></label>      <?php         $i++;        }        ?> </div> 

then in js:

$(':checkbox[name^=check]').each(function( ){     var nameid = 'check'+ (i+1);     this.id = nameid;     $(this).next('label').prop('for', nameid);  }); 

then jquery find checkboxes start name check, "check1", "checkblabla", etc...

and "$('#format').buttonset();" needs come after "for" change. fonts:

http://api.jquery.com/attribute-starts-with-selector/

edited:

i think dont need change js, can php, then:

<div id="format">     <?php      $i = 0;      $categories = get_categories();      foreach ($categories $category) { ?>      <input type="checkbox" name="check<?php echo $i ?>" value="<?php echo $category->cat_id; ?>">      <label for="check<?php echo $i ?>"><?php echo $category->cat_name;?></label>      <?php         $i++;        }        ?> </div> 

then in js:

$( "#format" ).buttonset(); 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -