I am new to jQuery, I need to get the element value from this input field
<input type="number" onkeypress="preventSomeKeys(event)" onchange="setTwoNumberDecimal(this)" name="fee_ctv_omp_percent" id="fee_ctv['omp_percent']" value="0.00" class="w-100" step="0.01" style="border:none;">
as you can see the id contains special chars.
I write this code,
var test2 = $("#fee_ctv['omp_percent']");
and this is the results:
Uncaught Error: Syntax error, unrecognized expression: #fee_ctv['omp_percent']
Is their a way to get the element by id in this scenario?
2
Answers
Try with:
For more info check https://api.jquery.com/id-selector/
You can use the escape selector:
$.escapeSelector("fee_ctv['omp_percent']")
and put it in your js like this:
working codepen
This way, you don’t have to manually escape every entry.
link to docs