Solved

Basic Javascript Help

Posted on 2014-11-03
6
143 Views
Last Modified: 2014-11-03
I have some basic HTML and assigned an ID

<div id="somecontent">48793748</div>

I want to find the number value of the div

so I know its something like

document.getElementById("somecontent")

I need to assign a variable and end up with the value being a number

If I do a document.getElementById("somecontent").innerHTML
I get "48793748" but its a string not a number.  How do I convert or change the getElementById so that it returns a number?
0
Comment
Question by:Baub Eis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40420040
parseInt(document.getElementById("somecontent").innerHTML)
0
 

Author Comment

by:Baub Eis
ID: 40420061
that drops info past the decimal point.

39.000329 returns 39

How can I get it to return the value of 39.000329 from the element?
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40420062
parseFloat(document.getElementById("somecontent").innerHTML)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Baub Eis
ID: 40420063
parseFloat got it
0
 

Author Comment

by:Baub Eis
ID: 40420066
so can I assign a variable with it?

var myvar = parseFloat(document.getElementById("somecontent.innerHTML)

?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40420117
Yep
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Print Rhino Java Array in Javascript 1 32
Help with Javascript to round decimal points to 2 13 31
Bootstrap question 4 26
Check input text, Number 6 28
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question