jquery - Javascript onclick function html -


i trying customize public git, , because noob in jquery/javascript not know how bind onclick function button, know how call getstates() function. yes know remove $(function(){ , work, want able call within jquery function ?

<!doctype html> <html> <head> <meta charset=utf-8 /> <title>us hospitals</title> <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> <script src='https://api.mapbox.com/mapbox.js/v2.2.3/mapbox.js'> </script> <link href='https://api.mapbox.com/mapbox.js/v2.2.3/mapbox.css' rel='stylesheet' /> <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <script src="/lib/neo4j-web.min.js"></script> </head> <body> <div id="desc">     <div class="row top-row">          <div class="col-xs-6">             <h3 class="heading">us hospitals</h3>         </div>         <div class="col-xs-6">             <p class="lead"></p>         </div>         <button onclick="$.getstates();">load states!</button>     </div> </div> <div id='map'></div> <script>  $(function(){      function getstates() {             session             .run(districtquery)             .then(function(result){                 result.records.foreach(function(record) {                      drawpolygons(parsewktpolygons(record.get("wkt")),  record.get("text"));                  });             })     } </script> </body> </html> 

i error saying :

uncaught typeerror: $.getstates not function @ htmlbuttonelement.onclick (index.html:51)

you add id button , use this:

<button id="load-states">load states!</button> 

javascript:

 $(function() {    function getstates() {     session         .run(districtquery)         .then(function(result){             result.records.foreach(function(record) {                  drawpolygons(parsewktpolygons(record.get("wkt")),record.get("text"));             });         })    } // adding event onclick button $('#load-states').on('click', getstates);                              }); 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -