File tree Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Expand file tree Collapse file tree 2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change 11
11
< script type ="text/javascript " src ="../../../ui/jquery.ui.checkbox.js "> </ script >
12
12
< script type ="text/javascript ">
13
13
$ ( function ( ) {
14
- $ ( "#check1, #check2, #check3" ) . checkbox ( ) ;
15
-
14
+ $ ( ":checkbox" ) . checkbox ( ) ;
16
15
} ) ;
17
16
</ script >
18
17
</ head >
19
18
< body >
20
19
21
20
< form >
22
21
23
- < input type ="checkbox " id =" check1 " /> < label for =" check1 " > Check 1</ label >
22
+ < label > < input type ="checkbox " / > Check 1</ label >
24
23
25
- < input type ="checkbox " id ="check2 " /> < label for =" check2 " > Check 2</ label >
24
+ < label > < input type ="checkbox " id ="check2 " /> Check 2</ label >
26
25
27
26
< input type ="checkbox " id ="check3 " /> < label for ="check3 "> Check 3</ label >
28
27
28
+ < input type ="checkbox " id ="check4 " /> < span > < label for ="check4 "> Check 4</ label > </ span >
29
+
30
+ < table >
31
+ < tr >
32
+ < td > < input type ="checkbox " id ="check5 " /> </ td >
33
+ < td > < label for ="check5 "> Check 5</ label > </ td >
34
+ </ tr >
35
+ </ table >
36
+
29
37
</ form >
30
38
31
39
</ body >
Original file line number Diff line number Diff line change 15
15
*/
16
16
( function ( $ ) {
17
17
18
+ var checkboxId = 0 ;
19
+
18
20
$ . widget ( "ui.checkbox" , {
19
21
20
22
_create : function ( ) {
21
23
22
- // find the checkbox's label
23
- this . labelElement = $ ( this . element [ 0 ] . ownerDocument ) . find ( "label[for=" + this . element . attr ( "id" ) + "]" ) ;
24
-
25
- // move the checkbox outside (before) the label if it's inside it
26
- if ( this . labelElement . has ( this . element ) . length ) {
24
+ // look for label as container of checkbox
25
+ this . labelElement = this . element . closest ( "label" ) ;
26
+ if ( this . labelElement . length ) {
27
+ // move the checkbox outside (before) the label
27
28
this . element . insertBefore ( this . labelElement ) ;
29
+
30
+ // the checkbox needs an id since it's no longer inside the label
31
+ if ( ! this . element . attr ( "id" ) ) {
32
+ this . element . attr ( "id" , "ui-checkbox-" + checkboxId ) ;
33
+ checkboxId += 1 ;
34
+ }
35
+
36
+ // associate label by for=id of checkbox
37
+ this . labelElement . attr ( "for" , this . element . attr ( "id" ) ) ;
38
+ } else {
39
+ // look for label by for=id of checkbox
40
+ this . labelElement = $ ( this . element [ 0 ] . ownerDocument ) . find ( "label[for=" + this . element . attr ( "id" ) + "]" ) ;
28
41
}
29
42
30
43
// wrap the checkbox in a new div
You can’t perform that action at this time.
0 commit comments