we simply use parseInt() function to convert string into integer:
Example1:
parseInt(”34px”);
-
Output: 34
Example2:
Size:
-
<script type="text/javascript">function incre()
-
{
-
var increase = 10;
-
wid = parseInt(document.getElementById(’style_class’).style.width);
-
document.getElementById(’style_class’).style.width = wid + increase;
-
}</script>
-
<table border="0">
-
<tbody>
-
<tr>
-
<td id="style_class" style="width: 80px; height: 50px; background-color: red;"></td>
-
</tr>
-
</tbody></table>
-
<strong>Size:</strong>
-
-
<input onclick="getElementById(’style_class’).style.width=’100′" name="botton" type="button" value="Size to 100" /> <input onclick="getElementById(’style_class’).style.width=’120′" name="botton" type="button" value="Size to 120" /> <input onclick="incre()" name="botton" type="button" value="Increase by +10" />
Post a Comment