?
Solved

Basic Javascript Help

Posted on 2014-11-03
6
Medium Priority
?
148 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 2000 total points
ID: 40420062
parseFloat(document.getElementById("somecontent").innerHTML)
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

This article discusses how to implement server side field validation and display customized error messages to the client.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

770 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