JQuery changing input text value not working

I'm trying to do it

$('input').val($('input').val()+"^2"); 

so each input field on the page (I have only one field) will have two additional letters ^ 2

it is strange that he adds only 2 and ignores the ^ character. any idea why this weird behavior is happening?

EDIT: The problem was that there was another part in the code that removed all characters from the input field after they were inserted. So I changed it to ignore this character. Thanks guys.

+4
source share
3 answers

Works for me: jsFiddle example .

+3
source

Try

 ^ 

or avoid carrots:

 /^ 

It displays as ^

+2
source

Try to slip away using backslash \

 $('input').val($('input').val()+"\^2");​ 

Or use the Unicode equivalent for carriage

CHECK FIDDLE

+1
source

Source: https://habr.com/ru/post/1439482/


All Articles