jQuery Sample

This is a jQuery program that rotates borders through css color settings. Style and script sections are included for demonstration purposes only. In a real world application they would be in separate files.

<!DOCTYPE html>
<html>
<head>
    <title>Color Test</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <style type="text/css">

        .color-box {
            color: #000000;
            font-size: 150%;
            border: 5px solid #ff0000;
            padding: 10px;
            margin: 10px;
        }
        .color-box a {
            color: #cccccc;
            margin-left: 10px;
        }

    </style>
    <script type="text/javascript">

        $(document).ready(function() {

            function getRandomColor() {
                var letters = '0123456789ABCDEF'.split('');
                var color = '#';
                for (var i = 0; i < 6; i++ ) {
                    color += letters[Math.floor(Math.random() * 16)];
                }

                return color;
            }

            $('.color-box a.make-rainbow').on('click', function () {

                var color = getRandomColor();
                var parentDiv = $(this).parent('div');
                parentDiv.css ('border', '5px solid ' + color);

                return false;

            });

            $('#make-rainbow a').on('click', function () {

                $('.color-box').each(function() {

                    var color = getRandomColor();
                    $(this).css ('border', '5px solid ' + color);

                });

                return false;
            });
        });


    </script>
</head>
<body>

    <h1>Color Test</h1>

    <div id="make-rainbow"><a href="#">Change ALL Color Boxes!!!!!</a></div>

    <div class="color-box">Color Box 1<a href="#" class="make-rainbow">Change this box color</a></div>

    <div class="color-box">Color Box 2<a href="#" class="make-rainbow">Change this box color</a></div>

    <div class="color-box">Color Box 3<a href="#" class="make-rainbow">Change this box color/a></div>

</body>
</html>