Skip to content

Commit 6c041ed

Browse files
staabmjzaefferer
authored andcommitted
Core: Improve elementValue method
Do not rewrap several times. Call .val() only when required. Closes #1055
1 parent 03cd4c9 commit 6c041ed

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/core.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,13 +558,15 @@ $.extend($.validator, {
558558
},
559559

560560
elementValue: function( element ) {
561-
var type = $(element).attr("type"),
562-
val = $(element).val();
561+
var val,
562+
$element = $(element),
563+
type = $element.attr("type");
563564

564565
if ( type === "radio" || type === "checkbox" ) {
565-
return $("input[name='" + $(element).attr("name") + "']:checked").val();
566+
return $("input[name='" + $element.attr("name") + "']:checked").val();
566567
}
567568

569+
val = $element.val();
568570
if ( typeof val === "string" ) {
569571
return val.replace(/\r/g, "");
570572
}

0 commit comments

Comments
 (0)