JSFiddle

  • zelect.js

    Enable styling the <select> the way you want by replacing it with a HTML variant. Changes in the HTML variant is reflected in the <select> (which now is hidden), so this should work in existing forms.

    /**
     * zelect.js is a jQuery plugin for making a <select> highly stylable
     * by replacing it with a HTML variant. Changes in ...</select>
  • Discrete sampling of Pi

    Use a discrete model to sample the value of Pi, instead of random samping.

    function computePi() {
        var diameter = parseInt($('#input').val());
        var inCircle = 0;
        var inSquare = diameter * diameter;
        
        
        for(var y = 0; y < diameter; y++)
            for(var x = 0; x < diameter; x++)
                if(inside(x,y))
                   inCircle++;
        
        
        document.getElementById('report').innerHTML =
            "<table>" +
                "<tr><td>Diameter ...</td></tr>
  • Animate changing the src-attribute of img-tag

    Someone asked me if you could animate changing the src-attribute on the img-tag. I gave him t his.

    function changeSrc(src, time) {
        time = time || 500;
        var $src = $('.src');
        function less() {
            var txt = $src.text();
            if(txt.length > 0 ...
  • Turn form input fields into name/value pairs

    Just a quick example to see what I come up with given little time.

    var form = document.getElementById("form");
    
    function collectElements(form) {
       // Fetch the interesting elements
       var input = form.getElementsByTagName('input');
       var text = form ...