Reputation: 321
I want to print an input type number on confirmation page.
var displayConfirm = function() {
$('#tab5 .form-control-static', form).each(function(){
var input = $('[name="'+$(this).attr("data-display")+'"]', form);
if (input.is(":radio")) {
input = $('[name="'+$(this).attr("data-display")+'"]:checked', form);
}
if (input.is(":text") || input.is("textarea")) {
$(this).html(input.val());
} else if (input.is("select")) {
$(this).html(input.find('option:selected').text());
} else if (input.is(":radio") && input.is(":checked")) {
$(this).html(input.attr("data-title"));
}
});
}
If I use input.is(":number")
and $(this).html(input.val());
it crashes.
Upvotes: 1
Views: 3449
Reputation: 36784
For completeness, you can register a jQuery pseudo selector if you wanted to stick with :number
:
$.expr[':'].number = function(el){
var $el = $(el);
return $el.prop('tagName').toLowerCase() == 'input' && $el.prop('type') == 'number';
}
.is(':number')
would then work perfectly fine for you.
Upvotes: 1
Reputation: 15555
$('#qwe').keyup(function () {
alert($(this).val());
});
To get value of input element use .val()
Upvotes: 0
Reputation: 82231
The reason it crashed because :number
is not valid selector.
You need to use attribute equals selector in .is()
condition:
input.is("[type=number]")
Snippet:
else if (input.is("[type=number]")) {
$(this).html(input.val());
}
Upvotes: 1