Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to autoclose paranthesis in javascript input

const closeChars = new Map([
  ['{', '}'],
  ['[', ']'],
  ['(', ')']
]);
    
maintextarea=document.getElementById('maintextarea');

maintextarea.addEventListener('input', function (e) {

    const pos = e.target.selectionStart;
    const val = [...e.target.value];
    
    const char = val.slice(pos-1, pos)[0];
    const closeChar = closeChars.get(char);
    
    if (closeChar) {
      val.splice(pos, 0, closeChar);
      e.target.value = val.join('');
      e.target.selectionEnd = pos;
    }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: Merger Douplicate array Object 
Javascript :: Iterating through document elements using for each in javascript 
Javascript :: material ui notify 
Javascript :: chanhe button yext jquery 
Javascript :: code postal leheriya tunisie 
Javascript :: javascript kommentare 
Javascript :: A simple javascript qr code generator 
Javascript :: finnhub 
Javascript :: validate url javascript 
Javascript :: compare two array value in javascript 
Javascript :: convert python to js online 
Javascript :: z-song laravel-admin unable load js fucntion untill use f5 
Javascript :: object property with space 
Javascript :: gatsby markdown link blank 
Javascript :: setstate to false after 10 sec react native 
Javascript :: display prety html json data 
Javascript :: The syntax of ScrollBy() methods 
Javascript :: Tims first jsom 
Javascript :: how to turn off auto refresh a href in javascript 
Javascript :: double and operator javascript 
Javascript :: use redis in adonis 
Javascript :: Using Math Functions in an IF statement 
Javascript :: vue apollo refetch every x ms 
Javascript :: javascript for sub set 
Javascript :: javascript array group duplicates 
Javascript :: settimeout react native focus text input 
Javascript :: This is an example of oligosaccharides: 
Javascript :: remove every element of array which starts with char text 
Javascript :: create dots in carousel react js bootraps 
Javascript :: javascript array game 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =