What is the equivalent of this script in jQuery (if a was an HTML element)?
a.value++; and ++a.value;
I assume it uses val(), but it seems inefficient to use:
a.val(a.val()+1);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
jQuery is JavaScript, and both
a++and++awork in JavaScript. I assume you are trying to increase the value of an input element by one – unfortunately there’s no shortcut to that. You just have to write:Remember to use
parseInt, otherwise the current value will be interpreted as a string and the 1 will be concatenated instead of added.a++won’t obviously work as in your case theais an jQuery object.