Saturday, 11 April 2015

How can I check DOM is ready in jQuery


How can I check DOM is ready in jQuery

Question: What is DOM?
The Document Object Model (DOM), is a model for representing and interacting with an XML, XHTML and HTML document.


Question: What is meaning of DOM is ready?
DOM is ready means html, images, css and java-Script are loaded fully.


Question: Why need to check if DOM is ready OR NOT?
Some times, we need to do the some modification in html tags like p,div and image etc.
We can change the DOM only after if DOM is loaded.


Following are 3 methods to check DOM() is fully loaded?
Method 1:
 jQuery(document).ready(function(){ 
      //consol.log('DOM IS FULLY loaded');

  });

Method 2:
$(function(){
  //consol.log('DOM IS FULLY loaded');
});  

Method 3:
if ( jQuery.isReady ) {  
    //consol.log('DOM IS FULLY loaded');
} 




How can I check whether Google Maps is fully loaded in GMaps v3


Problem 1: How can I check whether Google Maps is fully loaded in GMaps v3?
Problem Description: I want to add few codes just after the google map is fully loaded in browser.

Solution:
google.maps.event.addListenerOnce(map, 'idle', function(){
    // console.log('Google map is fully loaded in Gmap V3')
});

You can write your code inside this {}, It will be called when Google map V3 is fully loaded OR failed  to load due to any reason.



Problem 2: How can I change the color of a Google Maps marker In Gmaps 3?
Problem Description:
I want to change the color of default google markers
OR
want to show my image instead of default google marker.
var beachMarker = new google.maps.Marker({
  position: myLatLng,
  map: map,
  icon: 'mymarker.png'
});

Replace the "mymarker.png" with your image including path.