Question: Hello I am learning Google Map API from w3schools. I am new to JS and want to assign `location.lat()` and `location.lng()` to JavaScript variables. This is the copied code of tutorials. I am trying to assign the values as; 

`var latid=location.lat();` but I think `lat()` is returning nothing.

I have to save coordinates in database. If it is the wrong approach then please tell me what can I do to save `lnglat` coordinates in my database.

```
<!DOCTYPE html>
<html>
<head>
    <script src="http://maps.googleapis.com/maps/api/js?key=mykeyishidden&sensor=false"></script>
    <script>
        var map;
        var myCenter=new google.maps.LatLng(51.508742,-0.120850);

        function initialize() {
            var mapProp = {
                center:myCenter,
                zoom:5,
                mapTypeId:google.maps.MapTypeId.ROADMAP
            };

            map = new google.maps.Map(document.getElementById("googleMap"),mapProp);

            google.maps.event.addListener(map, 'click', function(event) {
                placeMarker(event.latLng);
            });
        }

        function placeMarker(location) {
            var marker = new google.maps.Marker({
                position: location,
                map: map,
            });

            var infowindow = new google.maps.InfoWindow({
                content: 'Latitude: ' + location.lat() + '<br>Longitude: ' + location.lng()
            });

            infowindow.open(map,marker);
        }

        google.maps.event.addDomListener(window, 'load', initialize);
    </script>
</head>

<body>
    <div id="googleMap" style="width:500px;height:380px;"></div>
</body>
</html>

```

Answer: 
If browser support isn't an issue, you could use the [`toggle()` method/`classList`](https://developer.mozilla.org/en-US/docs/Web/API/Element.classList#Summary).

[**Example Here**](http://jsfiddle.net/Qhsb2/)

```
(function () {
    var pElement = document.getElementsByClassName("normal")[0];
    pElement.addEventListener('click',function(){
       pElement.classList.toggle('change');
    });
} ());

```

[Browser support for `classList`](https://developer.mozilla.org/en-US/docs/Web/API/Element.classList#Browser_compatibility).
```
(function () {
    var pElements = document.getElementsByClassName("normal");

    for ( p in pElements ) {

        p.onclick = function () {
            if ( this.className.indexOf('normal') > -1 ) {
                this.className = 'change';
            } else {
                this.className = 'normal';
            }
        };

    }
} ());

```

Haven't tested yet but this should do the trick.