Reputation: 1
I want to get the value from json set when clicking event occur. and that value is stored in one variable and passed to function
html
<ul class="list-group">
<li class="list-group-item" id="Driver1">Driver1</li>
<li class="list-group-item id="Driver2"">Driver2</li>
<li class="list-group-item" id="Driver3">Driver3</li>
<li class="list-group-item" id="Driver4">Driver4</li>
<li class="list-group-item" id="Driver5">Driver5</li>
</ul>
Jquery
var driverLocation={
"Driver1":"12.98180953,77.44056702",
"Driver2":"12.89079587,77.35954285",
"Driver3":"12.81046221,77.44056702",
"Driver4":"12.85197115,77.74406433",
"Driver5":"13.17710836,77.8401947"
}
$(document).ready(function(){
$(".list-group-item").on("click", function(){
alert("hi");
var selection= $(this).attr('id');
var location=driverLocation[selection];
placeMarker(e.location,map)
});
});
It returns Uncaught ReferenceError: $ is not defined
Upvotes: 0
Views: 45
Reputation: 1871
You have to add jquery library and ensure correct order.
This is wrong usage:
<script src="my.js"></script>
<script src="jquery.min.js"></script>
Should be like this:
<script src="jquery.min.js"></script>
<script src="my.js"></script>
Upvotes: 0
Reputation: 1118
Correct like below and try
<li class="list-group-item id="Driver2"">Driver2</li>
to
<li class="list-group-item" id="Driver2">Driver2</li>
Upvotes: 0
Reputation: 10081
Do you have a jquery script tag in your head? If not you will need to add one as jQuery isn't packaged with browsers.
<head>
<script src="jquery-1.10.2.min.js"></script>
</head>
Upvotes: 1