How to increase div content value?
I want to increase div value +1 in certain events.How can i get div value and increas开发者_开发问答e it?
this.innerHTML = +this.innerHTML + 1;
DEMO
Given:
<div id="x">42</div>
You can do this:
var $x = $('#x');
$x.text(parseInt($x.text(), 10) + 1);
For your education:
.text()
parseInt()
(and always include the radix argument)
If the div's HTML is simply a number:
var element = document.getElementById('yourElementID');
element.innerHTML = parseInt(element.innerHTML, 10)+1;
Here you use below code
In javascript
--------------
var demoInt = $('#divInt').text();
demoInt =parseInt(demoInt);
In HTML
-------
<div id="divInt">111</div>
精彩评论