adsense

Friday, August 17, 2018

Find an element based on data- value

There are situations where we want to find element based on data- attributes. For instance we have to set validation message at run time for a given field.

In these situations we can use jQuery to easily find an element based on the  data- atttibutes as shown below.

 $('span[data-valmsg-for="' + fieldName + '"]');


cheers,
Samitha


Monday, August 13, 2018

jQuery checkbox OnChange

We can use jQuery to identify checkbox state change as shown below.

<script  type="text/javascript">

 funciton pageLoad() //can use either DOM Ready or pagLoad
{

   const chkSelectAll= $("#chkSelectAll");

   chkSelectAll.change(function(event) {
             var chkBox= event.target;
             if (chkBox.checked) {
               //Checkbox is checked
            } else {
              //Checkbox is unchecked
           }
});

}
</script>
Cheers,
Samitha