javascript - onBlur is not working on TextArea - Stack Overflow

I'm working on Value Formating based on input on Form Fields, for this purpose i'm using this

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, not input. You probably want input[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
Add a ment  | 

2 Answers 2

Reset to default 4

A 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

相关推荐

  • javascript - onBlur is not working on TextArea - Stack Overflow

    I'm working on Value Formating based on input on Form Fields, for this purpose i'm using this

    7小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信