It sounds like this in your code is not referring to your .btn element. Try referencing it explicitly with a selector:

var votevalue = parseInt($(".btn").data('votevalue'), 10);

Also, don't forget the radix.

Answer from Rory McCrossan on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_parseint.asp
JavaScript parseInt() Method
The parseInt method parses a value as a string and returns the first integer. A radix parameter specifies the number system to use:
🌐
SitePoint
sitepoint.com › blog › javascript › quick tip: how to convert a string to a number in javascript
Quick Tip: How to Convert a String to a Number in JavaScript — SitePoint
November 6, 2024 - The Number() function in JavaScript can be used to convert a string to a number. It takes a string as an argument and returns a number. If the string cannot be converted into a number, it returns NaN (Not a Number).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › parseInt
parseInt() - JavaScript - MDN Web Docs
The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › convert-a-string-to-an-integer-in-javascript
Convert a String to an Integer in JavaScript - GeeksforGeeks
July 11, 2025 - The number() method converts a string into an integer number. It works similarly to the unary plus operator.
Top answer
1 of 5
4

That is because string.split returns an array of strings.

If you want to handle each individual value returned by split, loop over the array and parse the items as numbers while iterating.

You can then do with the parsed number as you will. (in this example, it multiplies every number by two and appends the output)

var a = '1 - 2 - 3 - 4 - 5 - 6';
var splitarray = a.split('-')
    
for(var i=0; i < splitarray.length; i++)
{
  var valueAsInt = parseInt(splitarray[i]);
  //do whatever you want with valueAsInt, like for instance
  valueAsInt *= 2;

  //adding the br so we can see what the individual numbers are
  $('#resultDiv').append(valueAsInt + "<br />"); 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="resultDiv"></div>

2 of 5
2

parseInt will convert a single string, not an array of strings.

You can use jquery $.each to parse each item and return an array of int.

(putting this into html as in the question and the snippet below doesn't really mean much as it will convert back to string for the html, but the values can be manipulated once in the array).

var a = '1 - 2 - 3 - 4 - 5 - 6';
var arr = $.each(a.split('-'), function() { return parseInt(this, 10); });

var a = '1 - 2 - 3 - 4 - 5 - 6';
var b = $.each(a.split('-'), function() { return parseInt(this, 10); });
// b is now an array of ints
$("#result").html(b.join(","))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='result'>
</div>

🌐
Tutorialsrack
tutorialsrack.com › articles › 174 › how-to-convert-string-to-number-or-integer-in-javascript-or-jquery
How to Convert String to Number or Integer in javascript/Jquery
February 1, 2020 - To convert a string to a number or integer, javascript provides various functions such as Number(), parseInt(), parseFloat(), Math.floor(), Math.ceil(), Unary Operator(+) or Multiply by 1 which takes a string as input and returns an integer ...
Find elsewhere
🌐
Edureka Community
edureka.co › home › community › categories › web development › jquery › parseint with jquery
parseInt with jQuery | Edureka Community
June 9, 2022 - Can someone help me figuring out why the following jQuery code doesn't work? I want to return a integer ... parseInt($("#testid")); Thank you & bye!
🌐
freeCodeCamp
freecodecamp.org › news › javascript-convert-string-to-number-js-string-to-int-example
JavaScript Convert String to Number – JS String to Int Example
November 7, 2024 - You can use the floor() method, which will round down the passed value to the nearest integer. The ceil() method, which is the opposite of floor(), rounds up to the nearest integer.
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-a-string-into-integer-in-javascript
How to convert a string into an integer without using parseInt() function in JavaScript?
One way to convert a string into an integer is by using the unary plus operator (+). This operator converts its operand into a number.
🌐
Dotnettutorial
dotnettutorial.co.in › home › javascript › jquery convert string to number using parseint() function
Jquery convert string to number using parseInt() function
October 25, 2020 - Jquery convert string to number · parseInt() takes 2 parameter string and radix, the first parameter which value to be parsed, then returns an integer value or NaN. "radix" is used to specify which numeral system to be used for example a radix ...
🌐
Simplilearn
simplilearn.com › home › resources › software development › javascript tutorial: learn javascript from scratch › a guide to convert string to int in javascript
Convert String to an Int (Integer) in JavaScript | Simplilearn
June 14, 2026 - Learn how to convert string to an Int or Integer in JavaScript with correct syntax. Understand how to use the parseInt() method and find out examples for reference.
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
GreatFrontEnd
greatfrontend.com › questions › quiz › how-do-you-convert-a-string-to-a-number-in-javascript
How do you convert a string to a number in JavaScript? | Quiz Interview Questions with Solutions
September 5, 2021 - The most common ones are Number(), parseInt(), parseFloat(), and the unary plus operator (+). For example, Number("123") converts the string "123" to the number 123, and parseInt("123.45") converts the string "123.45" to the integer 123.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-convert-a-string-to-a-number-in-javascript
How to Convert a String to a Number in JavaScript
May 2, 2022 - The unary plus operator (+) will convert a string into a number. The operator will go before the operand. ... We can also use the unary plus operator (+) to convert a string into a floating point number.