Skip to content

Commit 55dc0bb

Browse files
committed
checkbox: fixed create to account for checkbox possibly being inside the label. Thanks to Steven Black for reminding me of this case.
1 parent 1f0710d commit 55dc0bb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ui/jquery.ui.checkbox.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@ $.widget( "ui.checkbox", {
1919

2020
_create: function() {
2121

22+
// find the checkbox's label
2223
this.labelElement = $( this.element[0].ownerDocument ).find( "label[for=" + this.element.attr("id") + "]" );
2324

25+
// move the checkbox outside (before) the label if it's inside it
26+
if ( this.labelElement.has(this.element).length ) {
27+
this.element.insertBefore( this.labelElement );
28+
}
29+
30+
// wrap the checkbox in a new div
31+
// move the checkbox's label inside the new div
2432
this.checkboxElement = this.element.wrap( "<div></div>" ).parent()
2533
.addClass("ui-checkbox")
2634
.append(this.labelElement);

0 commit comments

Comments
 (0)