2

i use google map in my newest project ,and i have a combo box which contain a lot of places , this combo has two attributes(longitude,latitude) when my page loads i have function that plot markers for all places within this combo this function is here :

//Set All mohafzat markers
    function setMohMarkers(){
    //Loop Through mohafzat Combo
    $("#moh").each(function(i){
    //Remove Old Markers
            //clearOverlays();
            //loop Through it's Options
            $('option',this).each(function(i){
            var midx=$(this).index();
            if(midx==0){
                //Don't Plot 0 Index item

            }else{
            var idx=$(this).index();//get Current Index
            var lon=$(this).attr('lng');
            var lat=$(this).attr('lat');
            var mname=$(this).text();
            //point's On Map
            var myLatlng = new google.maps.LatLng(lat,lon);

            //put Marker
            var marker = new google.maps.Marker({
              position: myLatlng, 
              map: map, 
              icon:image,
             //animation: google.maps.Animation.BOUNCE,
              title:mname
              }); 


             google.maps.event.addListener(marker, 'click', function() {
                map.setZoom(10);
                map.setCenter(marker.latlng);
                //Set mohafzat Combo to selected Marker
                //$("#moh option:contains(" + marker.title +")").attr("selected","selected");
                $('#moh option:[text="' + marker.title + '"]').attr('selected', true);

                //Trigger Change Function

                $("#moh option:contains(" + marker.title +")").trigger('change');

                });
                //push marker To my array(help me of deleting them :D)
                Allmarkers.push(marker);
            }});
            //End Click Function
    });
    }

this code works very fine on internet explorer ,put with firefox when i click the marker for first time it zoom in to the selected place and if i have selected (index 0) of (select) tag it call this function to plot all places again and zoom out of map to show them all (till here every thing is fine) but if i have clicked the same marker again it do nothing ! don't even put content of marker title at my combo box at this line :

$('#moh option:[text="' + marker.title + '"]').attr('selected', true);

what makes me nervous that this code works very will on IE !!!!

j0k
  • 22,600
  • 28
  • 79
  • 90
Samy Massoud
  • 4,295
  • 2
  • 35
  • 48
  • I don't think there is supposed to be a colon between `option` and `[text=...]`. I'm not sure how forgiving jQuery is with its syntax, but I would remove it anyway. – Cᴏʀʏ May 09 '11 at 20:04
  • which version of jQuery. the `attr` property was changed in 1.6: http://stackoverflow.com/questions/5874652/prop-vs-attr – Naftali May 09 '11 at 20:05
  • Do your option elements actually contain a text attribute? `[text=...]` checks the attribute named "text", [`:contains`](http://api.jquery.com/contains-selector/) checks for the contained text. You already have the correct version commented – Dan Manastireanu May 09 '11 at 20:11
  • i have tried both methods commented and current one and it's written correctly with jquery 1.6(as i told this code works with no any problem with IE AND I DON;T KNIW HOW ?) – Samy Massoud May 09 '11 at 21:51
  • should i post it as an answer, and ull mark as accepted? – Naftali May 09 '11 at 22:00

1 Answers1

3

The attr property was changed in jQuery 1.6:
See this question: .prop() vs .attr()

Community
  • 1
  • 1
Naftali
  • 144,921
  • 39
  • 244
  • 303