Question

I am a jQuery user and just learning YUI. I have the following code and I keep the error that YUI is not defined. I know it is an issue with linking to the library but I'm not exactly sure what. I had someone else test my code where they had YUI held locally and it worked fine. If I need to do this, how do I obtain a copy of the min.js file? When you download a copy from the YUI site its a tonne of files...

<head>
    <title>YUI3 Test</title
     <script src="http://yui.yahooapis.com/3.2.0/build/yui/yui-min.js"></script>


</head>
<body>
    <div id="menu">
        <p>Click here to test.</p>
    </div>

    <script>
        YUI().use('node', 'event', function (Y){
            var changeText = function(e){
                e.target.setHTML("<p>Now you see the test working.</p>");
            }

            var node = Y.one("#menu");
            node.on("click", changeText);

            //node.on("click", function(e){
            //    Y.one(node).load('menu.html');
            //});
        });
    </script>
</body>

Thanks!

Was it helpful?

Solution

You're missing a > after </title. This may be causing the script tag not to be recognized and so it's not loading.

Here it is broken: http://jsbin.com/ubaxoy/1/edit

And here it works after adding the missing >: http://jsbin.com/ubaxoy/2/edit

I also had to change setHTML to setContent because YUI 3.2 didn't have setHTML yet. I'd also recommend you to use a newer version of YUI, from 3.9.1 up. There have been a number of great additions since 3.2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top