Fixed header position jumps down when keypad is opened in IOS IPhone device only.

Fixed header position jumps down when keypad is opened

We can overcome this issue by using below script. The logic is when we focus the input elements only, keypad will open.

isiPhone method is used to detect the Iphone device.

 $("input,textarea").focus(function () {
   if (isiPhone()) {
        //Set of conditions When keypad is opened
      }).focusout(function () {
      if (isiPhone()) {
        //Set of conditions When keypad is closed

navigator.userAgent.match method also used to detect the devices.

Continue Reading

When scroll down change the header position to be fixed.

When scroll down change the header position properties

 function init() {
    window.addEventListener('scroll', function(e) {
        var distanceY = window.pageYOffset || document.documentElement.scrollTop,
        shrinkOn = 100,
        header = document.querySelector("header");
        if (distanceY > shrinkOn) {
            classie.add(header,"smaller"); // add class name when page scrolls
        } else {
            if (classie.has(header,"smaller")) {
window.onload = init();

When we scroll down, class smaller will add in header element. So, we can set the position: fixed property to smaller class. Otherwise smaller class will be removed.

Continue Reading

How to do Form Validation using Jquery?

Form Validation using Jquery

<head> <script src=""></script> <script src=""></script> </head>

We will see the Jquery validation for below sample form.

form validation
Required HTML codes for above form design.

<input name="firstname" type="text" value="firstname" />
<input name="lastname" type="text" value="lastname" />
<input name="email" type="email" value="email" />
<input type="button" value="submit" />

Add below CSS to differentiate the validation messages.


.error { 
border: 1px solid #b94a48; 
background-color: #fee; 


  $(function() {
  // Setup form validation on the #register-form element
 $("#register-form").validate({   //#register-form is form id
     // Specify the validation rules
rules: {
         firstname: "required", //firstname is corresponding input name
         lastname: "required",  //lastname:  is corresponding input name
         email: {               //email is corresponding input name
             required: true,
             email: true
     // Specify the validation error messages
messages: {
         firstname: "Enter First Name",
         lastname: "Enter Last Name",
         email: "Enter Valid Email ID",
         agree: "Please accept our policy"
     submitHandler: function(form) {


By using validate method we can define two arrays like rules and messages. In the rules, we can set the validation conditions to accept the given input. In the messages part, we should define the validation messages to show when the user entered the detail wrongly.

Continue Reading

How to Add tooltip when hovering on html element?

Implement tooltip when hovering element

We can implement tooltip by using below script.


//append tooltip
          jQuery('li .helptext').hover(function(){
             // Hover over code
                   var title = $(this).attr('alt');           
          }, function() {
                   // alert('test');
// Hover out code
          }).mousemove(function(e) {
                   var mousex = e.pageX + 20; //Get X coordinates
                   var mousey = e.pageY + 10; //Get Y coordinates
                   .css({ top: mousey, left: mousex })
          //tooltip end


Update the selector name based on your class name or id name.


.tooltip {
          border:1px solid #333;
          width: 250px;
          z-index: 999999;
          opacity: 1 !important;
.helptext {cursor:help;}
Continue Reading

How to Change the background color of odd and even row?

Change the background color for odd and event panel of accordion

‘Odd’ and ‘even’ pseudo classes are used to selecting the odd and even number of row.


    $('.panel-group > .panel-default:even').addClass('even');
    $('.panel-group > .panel-default:odd').addClass('odd');

By using odd and even classes we can set the required background color using CSS.

Continue Reading

How to detect Browser feature using Modernizr?

Browser feature detection using Modernizr Plugin

Before discussing about runtime approach using modernizr, we will see couple of browser based approach.


These websites are useful to identify the browser supports for HTML5 features and related specifications.


Modernizr is ajavascript library. It detects either user browser is supporting HTML and CSS3 features or not. It is very useful to detecting HTML5 and CSS3 features Using this feature detection support, developers can try some alternative approaches to implement the same kind of feature in that unsupported browsers.

First we should embed the Modernizr js file in head section.

<script src="modernizr.js"></script>

To check video feature support in different browsers, we can use the following script.

//Example 1:
if( == false)
//alert("Browser doesn't support HTML5 Video");

//Example 2:
To check camvas feature support in different browsers, we can use the following script.
if("geolocation" in navigator) {
  navigator.geolocation.getCurrentPosition(function(position) {
    // show the location on a map by using the Google Maps API
} else {
  // showing static map image

Continue Reading

How to do Drag and Drop feature using HTML5 API?

Drag and Drop feature implementation

We should use html event attributes like ondragover, ondrop and ondragstart to achieve drag and drop feature.


<div draggable = "false">
<!-- ondragover event: Specifies where the dragged data can be dropped -->
<!-- ondrop event: When the dragged data is dropped, a drop event occurs -->
<div id="div1" 
             style="width: 300px; height: 300px; padding: 10px; border: 1px solid #FF4500;"
             draggable = "false">
<!--ondragstart = Specify what should happen when the element is dragged -->
             id="drag1" src="HTML5.jpg" 
    width="204" height="204" />


        function drag(event){
         // set the target element
        function allowDrop(event){
            //To allow a drop, we must prevent the default handling of the element
        function drop(event){
            //To allow a drop, we must prevent the default handling of the element
         // append drag element in to drop area
            var controlId = event.dataTransfer.getData("ControlID");


  • ondragover event: It specifies when an element is dragged over a drop target.
  • ondrop event: When the dragged data is dropped, a drop event occurs.
  • Ondragstart: It specify what should happen when the element is dragged.
  • event.preventDefault() – Prevent the default behavior of an element.
Continue Reading