jQuery to check if css custom checkbox has been checked -


i had build custom checkbox using following css:

  input[type="checkbox"] {       display:none;   }   input[type="checkbox"] + label span {       display:inline-block;       width:19px;       height:19px;       margin:-1px 4px 0 0;       vertical-align:middle;       background:url("../image/checkbox.png") 0 -20px no-repeat;       cursor:pointer;   }   input[type="checkbox"]:checked + label span {       background:url("../image/checkbox.png") 0 -1px no-repeat;   } 

however having problem in checking if checkbox checked or not following function:

var radio_check = $('#one input[type="checkbox"]');      function add_color(element, color){         element.css('background-color', color);     }      function checkemailformat(){         if(emailreg.test(emailaddressval)) {             add_color(email, red);         }         else {             return true;         }     }      function check_radio_checkb(){         if(!radio_check.is(':checked')){             alert('no');         }         else{             alert('yes');             // return true;         }     }      function validate_form(){          $('form input:not(.email input), textarea').each(function(){             if ($(this).val() == '') {                 add_color($(this), red);             }             else {                 add_color($(this), white);             }          });          return (checkemailformat() && true);      }                               <div class="checkbox_wrapper">                                  <input type="checkbox" id="one" />                                 <label for="one">                                     <span></span>                                     agree the terms , conditions and privacy policy                                 </label>                                 <input type="checkbox" id="two" />                                 <label for="two">                                     <span></span>                                     join kruĊĦovice vips latest news, competitions , promotions.                                  </label>                              </div> 

hey try js code instead of yours.it gives result expected.

$('input[type="checkbox"]').change(function(){ check_radio_checkb($(this));  }); function add_color(element, color){     element.css('background-color', color); }  function checkemailformat(){     if(emailreg.test(emailaddressval)) {         add_color(email, red);     }     else {         return true;     } }  function check_radio_checkb(rdb_new){     if(!rdb_new.is(':checked')){         alert('no');     }     else{         alert('yes');         // return true;     } }  function validate_form(){      $('form input:not(.email input), textarea').each(function(){         if ($(this).val() == '') {             add_color($(this), red);         }         else {             add_color($(this), white);         }      });      return (checkemailformat() && true);  } 

hope works.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -