What I’m attempting to do can be accomplished by the following…
elementContent = document.getElementById('docElement').innerHTML;
elementContent = parseFloat(elementContent);
or even by…
elementContent = parseFloat( document.getElementById('docElement').innerHTML );
but I can’t help to wonder if there’s a more elegant way to retrieve and assign DOM content as a float that I may be unaware of. Any insight?
There is the unary plus operator which tries to convert a string (or another type’s
toString()) to a number. It would be used like:As others have mentioned you can use jQuery as essentially syntactic sugar for .innerHTML here, also.