use name attribute for input instead of id for use with label

you need Jquery:

1
2
3
4
5
6
<label for="myinput"></label><input name="myinput" type="text" value="text here" />
$('label').live('click', function(e){
        if( $(e.target).is(':input') ) return;
        var i = $(':input[name="' + $(this).attr('for') + '"]')
        i.is(':checkbox') ? i.attr('checked', !i.attr('checked') ) : i.focus().select();
    })

Recommended posts:


Tags : checkbox form HTML input jquery label select

This entry was posted on Saturday, December 5th, 2009 at 3:54 pm and is filed under Blog. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


 Top