JavaScript this value of input field .val() not a function this.value input,this.value input javascript,this value input

I have this jquery code to check for any value on a given input and then add a simple class if the input has a value.

But in console i receive error that .val() is not a function?

my code is:

$.fn.tkFormControlMaterial = function(){
        this
            .blur(function () {
                if (this.val())
                    this.addClass('used');
                else
                    this.removeClass('used');
            })
            .after('<span class="ma-form-highlight"></span><span class="ma-form-bar"></span>');
    };
Answer:1

bind will set you free

$.fn.tkFormControlMaterial = function(){
        this
            .blur(function () {
                if (this.val())
                    this.addClass('used');
                else
                    this.removeClass('used');
            }.bind(this))
            .after('<span class="ma-form-highlight"></span><span class="ma-form-bar"></span>');
    }.bind(this);
Answer:2

I found the solution.

If anyone needs a working sample of my own code above:

$.fn.tkFormControlMaterial = function(){
        $(this)
            .blur(function () {
                if ($(this).val())
                    $(this).addClass('used');
                else
                    $(this).removeClass('used');
            })
            .after('<span class="ma-form-highlight"></span><span class="ma-form-bar"></span>');
    };
Answer:3

I am having a bit of trouble getting momentjs to convert a date to unix in the correct way: var start = new Date(2013,11,2); console.log('Start date: '+start); console.log('Unix date: '+moment(start)....

I am having a bit of trouble getting momentjs to convert a date to unix in the correct way: var start = new Date(2013,11,2); console.log('Start date: '+start); console.log('Unix date: '+moment(start)....

  1. moment js convert unix timestamp to date
  2. moment js convert unix timestamp to utc date
  3. moment js convert unix timestamp
  4. moment js convert unix to date
  5. moment js convert unix
  6. moment js format unix
  7. moment js format unix timestamp
  8. moment js convert to unix
  9. moment js convert to unix time
  10. moment js format unix time
  11. moment convert unix timestamp to date
  12. moment.js unix timestamp to date
  13. moment js unix timestamp to date

I am wondering if there is some better way to communicate between distant components. In my case I have structure like this: <div> <History /> <Board> <BoxesView> ...

I am wondering if there is some better way to communicate between distant components. In my case I have structure like this: <div> <History /> <Board> <BoxesView> ...

  1. passing data from child to parent react
  2. passing data from one component to another
  3. passing data from child to parent angular
  4. passing data from parent to child
  5. passing data from controller to view
  6. passing data from php to javascript
  7. passing data from child to parent vue
  8. passing data from activity to fragment
  9. passing data from view to controller in mvc
  10. passing data from laravel to vue
  11. passing data from child to parent react hooks
  12. passing data from flask to javascript
  13. passing data from html to javascript
  14. passing data from rails to react
  15. passing data from child to child react
  16. passing data from one fragment to another
  17. passing data from controller to view laravel
  18. passing data from one lambda to another
  19. passing data from jsp to servlet
  20. passing data from iframe to parent

-- Hi ! Reader, if you are not comfortable with Tumblr, please tell me, I will give more details! I had some issues on my tumblr page with the default theme 'Optica'. When I post an embed SoundCloud ...

-- Hi ! Reader, if you are not comfortable with Tumblr, please tell me, I will give more details! I had some issues on my tumblr page with the default theme 'Optica'. When I post an embed SoundCloud ...

I would like to dynamically remove or disable a <style> tag that looks like this <style type="text/css" id="cssx/portal/simple-sidebar.css" designtr="cssx/portal/simple-sidebar.css"> #...

I would like to dynamically remove or disable a <style> tag that looks like this <style type="text/css" id="cssx/portal/simple-sidebar.css" designtr="cssx/portal/simple-sidebar.css"> #...

  1. find style attribute using jquery
  2. jquery find style attribute
  3. jquery find style attribute value
  4. javascript find style attribute
  5. find element by style attribute jquery
  6. jquery find inline style attribute