SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    167
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Click Event Only Fires Once

    I am integrating the google maps api into my application on the map it has an info window that will display information about a marker / cluster in that location. My problem is that when the map loads, the $('next') click event will only fire once. Once I close the info window and open another info window the $('next') click event won't fire. I find this to be odd because both times I am creating and destroying the next link element. What am I doing wrong?

    Code:
    google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
    	var markers = cluster.getMarkers();
    	var html2 = '';
    	  
    	html2 += '<div id="infoWin">';
    	html2 += '<ul class="addrlist">';
    	
    	for (var i=0; i < markers.length; i++){
    		if(i > 0){
    			html2 += '<li style="display: none;">' + markers[i].html + '</li>';
    		}else{
    			html2 += '<li class="first">' + markers[i].html + '</li>';
    		}
    		
    	}
    	
    	html2 += '</ul>';
    	html2 += '<div style="position: relative; bottom: 0;"><a id="next" class="f_right pts" href="javascript: void(0)">Next</a></div>';
    	html2 += '</div>';
    	
    	infowindow.setContent(html2);
    	infowindow.open(map, markers[0]);
    	
    	$('#infoWin').parent().css({overflow: 'hidden'});
    	
    	$('ul.addrlist li').click(function() {
    		var p = $(this).find("a").attr("rel");
    		return infopop(markers[p]);
    	}); 
    
    	$('#next').click(function() {
    		console.log('test');
    		var toHighlight = $('.first').next().length > 0 ? $('.first').next() : $('#infoWin li').first();
    		$(this).fadeOut(100);
    		$('.first').fadeOut(100);
    		$('.first').delay(100).removeClass('first');
    		toHighlight.delay(100).addClass('first');
    		$('.first').delay(100).fadeIn(100);
    		$(this).delay(100).fadeIn(100);
    	});
    });

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Your scripting code seems to be affecting all elements on the page with a class of first.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •