Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    binding problems

    hey guys,
    i have this code, and i dont know why it doesn't work.
    what i want it to do is when the link is clicked a message will be shown inside the div with the "la" id.

    Code:
    <html>
    <head>
    	<title>NoNe</title>
    
    	<script type="text/javascript" src="jquery.js"></script>
    <script>
    
    var foo=function(e){
            e.preventDefault();
    	$('#la').html('hello world');
    	};
    
    $('#physics').click(foo);
    </script>
    </head>
    <body>
    <div id="la"></div>
    <a href="javascript:void(0)" id="physics">Physics Section</a>
    
    </body>
    </html>
    thanks in adv.

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,955
    Thanks
    9
    Thanked 726 Times in 720 Posts
    You need to wrap your click handler within a document ready call:

    Code:
    $(document).ready(function(){
    $('#physics').click(foo);
    });

  • #3
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks!
    i've also noticed that by moving the code-lines after the divs, it works fine.


  •  

    Posting Permissions

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