0

I have some input

<input id = 'some_id' type='text'/>

I want to set value with backslash, for example:

$('#some_id').val('someval \') 

and I'm getting error:

Uncaught SyntaxError: Invalid or unexpected token

How can I show string value with backslash in input ?

0

1 Answer 1

1

Escape the \ character like this: $('#some_id').val('someval \\')

$('#some_id').val('someval \\') 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id = 'some_id' type='text'/>

Sign up to request clarification or add additional context in comments.

5 Comments

how can I do it dynamically ? when I'm getting some string variable and I don't know how it looks like ?
@godot did you ask a separate question for this? or did you vote to reopen the original one? I'm asking because I think it would be good to do that in order to see it in context with this new requirement. Let me know...
you think that I should ask new question about it?
@godot I think so, because it would be good to see it as you describe it now, besides it would be too difficult to answer in a comment and if I update the answer it won't help future readers because the original post states a different thing (it doesn't talk about the dynamic part). Drop a link here with the new question.
okay, I accepted your answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.