Pages

Tuesday, February 15, 2011

jQuery Plugin - table

/**
 * This plugin provide stylesheet for table.
 * 
 * @author   : irfanudin ridho
 * @email    : irfan.ub@gmail.com
 * @version  : 1.0
 * @date     : February 15, 2011
 * 
 * The structure of the table is like this
 * <table>
 * <tr><th>Name</th><th>City</th></tr>
 * <tr><td>Lady Gaga</td><td>New York City</td></tr>
 * <tr><td>Luna Maya</td><td>Denpasar</td></tr>
 * </table>
 */

<script>
(function($){
    $.fn.table = function(){
        $(this).addClass('jq-table');
        $(this).find('th').addClass('jq-th');
        $(this).find('td').addClass('jq-td');
        $(this).find('tr:odd').addClass('jq-tr-odd');
        $(this).find('tr:even').addClass('jq-tr-even');
        $(this).find('tr').mouseover(function(){
            $(this).addClass('jq-tr-hover');
        });
        $(this).find('tr').mouseout(function(){
            $(this).removeClass('jq-tr-hover');
        });
        $(this).find('tr:first').addClass('jq-tr-first');
        $(this).find('tr:first').mouseover(function(){
            $(this).removeClass('jq-tr-hover');

        });

        return this;
 };
})(jQuery);

</script>

<style>
.jq-table { width: 100% }
.jq-tr-odd { background: #efe; }
.jq-tr-even { background: #fef; }
.jq-tr-first { background: #ccf; color: #444; }
.jq-tr-hover { background: #af5; }
.jq-td { font: 12px arial; padding: 2 0 2 10px; color: #444; }
.jq-th { text-align: left; padding: 2 0 2 10px; }
</style>

No comments:

Post a Comment