I'm working on Value Formating based on input on Form Fields, for this purpose i'm using this selector
jQuery( "input[name*='socialtag']" ).blur(function() {
var value = jQuery(this).val();
alert(value);
});
i also use alternative like this:
jQuery(document).on('blur', 'input[name*=\'socialtag\']', function () {
var value = jQuery(this).val();
alert(value);
});
Both are working for the input field, but it's not working for the TextArea field. Is there something i miss ?
I'm working on Value Formating based on input on Form Fields, for this purpose i'm using this selector
jQuery( "input[name*='socialtag']" ).blur(function() {
var value = jQuery(this).val();
alert(value);
});
i also use alternative like this:
jQuery(document).on('blur', 'input[name*=\'socialtag\']', function () {
var value = jQuery(this).val();
alert(value);
});
Both are working for the input field, but it's not working for the TextArea field. Is there something i miss ?
Share Improve this question asked Aug 23, 2015 at 18:50 Viktor IwanViktor Iwan 892 silver badges11 bronze badges 2-
11
A textarea's CSS selector is
textarea
, notinput
. You probably wantinput[name*=\'socialtag\'], textarea[name*=\'socialtag\']
– blex Commented Aug 23, 2015 at 18:51 - 3 @blex, Be sure to add this as an answer to the question so you get credit for it. – idream1nC0de Commented Aug 23, 2015 at 19:01
2 Answers
Reset to default 4A textarea's CSS selector is textarea
, not input
.
So, to select both, you can do this:
jQuery(document).on('blur', 'input[name*=\'socialtag\'], textarea[name*=\'socialtag\']', function () {
var value = jQuery(this).val();
alert(value);
});
How CSS selectors work (the basics):
Selectors that start with a
#
select an element with a certain ID.Selectors that start with a
.
select elements with a certain class.Selectors that have nothing in front of them select elements with a certain tag name (ie
div
,span
,input
,textarea
...).
In HTML, TextArea is a TAG itself. It's not a type of input field. Hence trying to find an input with that name won't work. Try this :
jQuery( "textarea[name*='socialtag']" ).blur(function() {
var value = jQuery(this).val();
alert(value);
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745300072a4621382.html
评论列表(0条)