javascript will not work onload

Posted by user2711818 on Stack Overflow See other posts from Stack Overflow or by user2711818
Published on 2013-10-20T15:51:26Z Indexed on 2013/10/20 15:53 UTC
Read the original article Hit count: 102

Filed under:

The javascript on the page needs to work onpage load. So I tried adding the document ready function into the code. It doesn't seem to work.

http://janeucreative.com/daddychallenge/bag.html

<script>$(document).ready(function() {


  function addItem(item) {
        var itemInCart = item.cloneNode(true);
        itemInCart.onclick = function() { removeItem(this); };

        var cart = document.getElementById("cart");
        cart.appendChild(itemInCart);
    }

    function removeItem(item) {
        var itemInItems = item.cloneNode(true);
        itemInItems.onclick = function() { addItem(this); };

        var cart = document.getElementById("cart");
        cart.removeChild(item);
    }
  init();
});</script>

Any advice would be much appreciated! I'm very new to javascript and just trying to learn it a step at a time.

© Stack Overflow or respective owner

Related posts about JavaScript