SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Function not working

    Hey,

    Im not sure why this isnt working, when I click the button the function doesnt seem to get called...

    Code javascript:
    $(document).ready(function(){	
     
    	$('.vwidget').children('a').click(function(){
    		var a = $(this).attr("id");		
    		if(a == 1)
    		var container = 'upcount';
    		else
    		var container = 'downcount';
     
    		$.post("rating.php?value="+a, {
    		}, function(response){
    			//$('.upcount').fadeOut();
    			$('.'+container).html(unescape(response));
    			$('.'+container).fadeIn();	
    		});
    	});	
     
    	$('#diggs0').click(function(){
     
    		$.post("rating.php?v=1", {
    		}, function(response){
    			$('#diggs-strong').html(unescape(response));
    			$('#diggs-strong').fadeIn();	
    		});
    	});	
    });

    Code HTML4Strict:
    <div style="float:left;">
    			<div class="digg-count">
    			<a  href="#" ><strong id="diggs-strong" style="opacity: 100;"><?php echo $row3['rating']?></strong><br /> diggs</a>
    			</div>
    			<div id="diggit"><a href="#" id="diggs0">diggs</a></div>
    		</div>
    Last edited by ScallioXTX; Jul 4, 2010 at 09:54. Reason: Added BB tags to make the code look pretty :-)

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's probably because of your use of the children method.

    children() only goes one level deep. You probably want to use find(), or just $('.vwidget a').

    If that's not the problem, you need to do a bit of debugging. Find out where exactly the failure is happening. Example:

    Code javascript:
    $(document).ready(function(){   
     
        $('.vwidget').children('a').click(function(){
            alert('click!'); // something's been clicked!
            var a = $(this).attr("id");
            alert(a); // check for the ID  
            if(a == 1)
            var container = 'upcount';
            else
            var container = 'downcount';
     
            $.post("rating.php?value="+a, {
            }, function(response){
                alert(response); // check for result of ajax request
                //$('.upcount').fadeOut();
                $('.'+container).html(unescape(response));
                $('.'+container).fadeIn(); 
            });
        }); 
     
        $('#diggs0').click(function(){
     
            $.post("rating.php?v=1", {
            }, function(response){
                $('#diggs-strong').html(unescape(response));
                $('#diggs-strong').fadeIn();   
            });
        }); 
    });


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
  •