Tested on
- IE 6.0
- Firefox 1.5/2.0
- Opera 9.02
- Safari 2.0.4
Examples
Test 1 : simple test on checkbox
Click in a checkbox. It's wrap into a div element.
In all browsers except IE, the checkbox preserve the checked state.
$('input[@type="checkbox"]', $('#test1')).click( function(){ if( $( '#c1' ).length == 0 ) { alert( "Checkbox is checked." ); $(this).wrap( '<div id="c1" class="error" style="display:none;"></div>' ) $('#c1').fadeIn(400); alert( "Checkbox is always checked ?" ); } });
Test 2 : wrap $(this).parents( ':not("label")' ).eq(0)
Click in a checkbox (It's possible to click on label).
This first parent (not label element) is wrap into a div.
In all browsers except IE, the checkbox preserve the checked state.
$('input[@type="checkbox"]', $('#test2')).click( function(){ if( $( '#c2' ).length == 0 ) { alert( "Checkbox is checked." ); $(this).parents( ':not("label")' ).eq(0).wrap( '<div id="c2" class="error" style="display:none;"></div>' ); $('#c2').fadeIn(400); alert( "Checkbox is always checked ?" ); } });
Test 3 : with append method
Click in a checkbox (It's possible to click on label).
This first parent (not label element) is wrap into the target div.
In all browsers except IE, the checkbox preserve the checked state.
This result is similar with the prepend method.
Target of DOM manipulation.
$('input[@type="checkbox"]', $('#test3')).click( function(){ alert( "Checkbox is checked." ); jParent = $(this).parents( ':not("label")' ).eq(0); $('#c3').append( jParent ); alert( "Checkbox is always checked ?" ); });