Wednesday, 15 May 2013

javascript - jquery checkbox if check/uncheck do this -



javascript - jquery checkbox if check/uncheck do this -

individual refinements can selected , de-selected user clicking on various checkboxes. when panel has number of facets selected, “clear” button needs shown. when panel has facets selected, “clear all” button needs shown @ top of refinements controls.

so based on getelementbyid should able accomplish this, i'm not able myself.

// 'getting' data-attributes using getattribute var size = document.getelementbyid('size'); var base of operations = document.getelementbyid('base_colour'); var brand = document.getelementbyid('brand'); //when panel has number of facets selected, “clear” button needs shown $('input').on('click', function(){ if ($('.option input:checkbox:checked').length > 0) { // 1 checked } else { // none checked } });

http://jsfiddle.net/fsrdd5yz/

you can like

var $clearall = $('.refinements > .clear-filter'), $checks = $('.options input[type="checkbox"]'), $clear = $('.refinements .panel .clear-filter'); $checks.change(function () { var $options = $(this).closest('.options'), $clear = $options.prev(); //if current checkbox checked can show , clear buttons if (this.checked) { $clear.show(); $clearall.show(); } else { //if uncheck operation set visibility based on overall state of respective checkboxes $clear.toggle($options.find('input[type="checkbox"]').is(':checked')) $clearall.toggle($checks.is(':checked')) } }) $clearall.click(function (e) { e.preventdefault(); $checks.prop('checked', false); $(this).hide(); $clear.hide(); }) $clear.click(function (e) { e.preventdefault(); $(this).next().find('input[type="checkbox"]').prop('checked', false); $clearall.toggle($checks.is(':checked')); $(this).hide(); })

demo: fiddle

javascript jquery checkbox getelementbyid

No comments:

Post a Comment