views:

82

answers:

1

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);

+6  A: 
Tatu Ulmanen
Until now, I never had trouble a++ or ++a misinterpreting something as string. Quick note though: According to jQuery Cookbook, ++a executes faster than a++. The difference is minimal though and can be ignored if you aren't in a massive loop
Mike
`parseInt(..., 10)` to avoid octal problems. `+1` or on its own will cast to `Number`, not necessarily an integer.
bobince