javascript - What's the difference between a regular js int and one from jquery.val()? -


i'm using script called countup.js increments integer in animated way until reaches it's desired amount.

here code:

html:

<h2 id="countup-1">2500</h2> 

js

var theval = 5000; var demo = new countup("countup-1", 0, theval, 0, 2.5); demo.start(); 

this animates counter 0 5000. perfect.

but want animate value in h2 tag (2500). tried this.

var theval = parseint($('#countup-1').val()); var demo = new countup("countup-1", 0, theval, 0, 2.5); demo.start(); 

but error: "uncaught typeerror: c.match not function"

how be? i'm sending int countup function in both cases?

set fiddle here:

https://jsfiddle.net/0yawm9jr/

$('countup-1').val() doesn't exist (there no value attribute on specific element). try (see working jsfiddle):

var theval = 5000; var demo = new countup("countup-1", 0, theval, 0, 2.5); demo.start();  var theval2 = parseint($('#countup-2').html().split(',').join('')); var demo2 = new countup("countup-2", 0, theval2, 0, 2.5); demo2.start(); 

the jquery method .val() retrieves contents of value attribute of element. in case, you're using html element innerhtml set value. therefore, need call $(yourelement).html().

also, number contains commas, need split number @ commas rejoin no non-numerical characters.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -