JSFiddle - React, Tailwind, and code Playground

HTML

how to save the value of INPUT in variable to not to write a lot of duplicate code?

<div id="form">
    1. with class: <input type="text" class="set-default" value="title" /><br/>
    2. without class: <input type="text" value="value" /><br/>
    3. empty value: <input type="text" class="set-default" value="" /><br/>
</div>

JavaScript

$(function(){
    $('.set-default').bind({
    focus: function(){
        if(typeof($(this).data('def')) == 'undefined'){
               $(this).data('def', this.value)
        }
        if(this.value == $(this).data('def')){
           this.value = '';
        }
     },
     blur: function(){
       if(this.value == ''){
          this.value = $(this).data('def');
       }
     }
    })
});