SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery Function Not Working

    Hi all, I'm a little stuck on the following code. I have a button that when clicked, I want to change the content of a DIV. Please see my code below. I'm connecting to the library as I'm using a few others bits and pieces of jQuery.

    Code JavaScript:
    $(document).ready(function(){
     
    function addtoBasket(id){
        $(".productDescription").html("Hello World :)");
    }
     
    })

    Code HTML4Strict:
    <input type="button" value="&nbsp;" name="cartadd" id="buyNow" onclick="addtoBasket(464)">

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,191
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Functions wrapped in an anonymous function cannot be used outside of it, simple remove the jQuery DOM ready method and it will work fine.


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
  •