javascript - in relation to loading jquery into a particular div -


could me code?

in rails project (i don't think matters project is) have header fixed in position, called 'fixed_header'. there links on page, load new pages underneath, when clicked.

one of pages loads, when clicked, has div called 'map_canvas'. want code in 'fixed_header' page check existence of div called 'map_canvas', , then, if there, load map it.

my code below taken snippets throughout application, work, can't make work particular thing. appreciated.

<script>    //is 'ready' code use? code in 'fixed_header'   //my idea that, once    //a link in 'fixed_header' clicked, new page loads   //underneath header. div 'map_canvas'   //searched , function activates if found.      $(document).on("ready", function () {          if ($("#map_canvas").length > 0) {              initialize_google_maps();          }      });      function initialize_google_maps() {          var currentlatlng = new google.maps.latlng(user_latitude, user_longitude);         var zoom = 10;         var myoptions = {             zoom: zoom,             center: currentlatlng,             maptypeid: google.maps.maptypeid.roadmap, // roadmap, satellite, hybrid             streetviewcontrol: false         };         map = new google.maps.map(document.getelementbyid("map_canvas"), myoptions);          var marker = new google.maps.marker({             map: map,             position: currentlatlng,             icon: {                 oppacity: 0             }         });          var circle = new google.maps.circle({             map: map,             fillopacity: 0,             strokeweight: 2,             strokeopacity: 0.7,             radius: 10000,         });         circle.bindto('center', marker, 'position');     } </script> 

because want check div existence in real time when user clicks on link should change code

$(document).on("ready", function () {          if ($("#map_canvas").length > 0) {              initialize_google_maps();          }      }); 

as below

$('a').live('click',function() {         if ($("#map_canvas").length > 0) {              initialize_google_maps();          } } 

use anchor selector according link classes or ids.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -