javascript - Retrieving value of b with getElementByTagName and making it integer -


first of all, new javascript. have been pulling hair getting work. have tried lot of different approaches, cannot working. want do, pull value html document javascript, , save value from: <div class="sum">sum of order: <b>530 sek</b></div>. want grab integer, 530, , strip of else.

html:

<div class="order">         <div id="departdate">         <div><b>departing:</b></div>         <div>2015-08-08</div>     </div>          <div id="returndate">             <div><b>returning:</b></div>             <div>2015-08-16</div>         </div>          <div><b>tickets</b></div>          <table>             <tbody><tr>             <td class="first">adult(s)</td>             <td>1 x</td>             <td>530 sek</td>             </tr>             <tr class="noborder">         <td colspan="3">         <table>         <tbody><tr>         <td id="people102" class="query first" style="font-size: 11px;">test testsson</td>         <td id="info102" class="query text-red" style="font-size: 11px;"></td>         </tr>         </tbody></table>         </td>         </tr>          <tr>             <td class="first">children:</td>             <td>3 x</td>             <td>0 sek</td>         </tr>         <tr class="noborder">             <td colspan="3">         <table>         <tbody><tr>             <td id="people9999" class="query first" style="font-size: 11px;"></td>             <td id="info9999" class="query text-red" style="font-size: 11px;"></td>         </tr>         </tbody></table>         </td>         </tr>         </tbody></table>         <div class="sum">sum of order: <b>530 sek</b></div>         <div class="vat">vat 6%: 30 sek</div> </div> 

what have been figuring i'd try do, grab <b> value through document.getelementsbytagname("b")[3]; isn't working when try either parse or replace using regexp. full example of trying do:

function my(){  var b = document.getelementsbytagname("b")[3];  var str = b.tostring().replace(/[^0-9]/g, '');  var x = str.parseint();  return x }  my(); 

this says str.parseint not function. if strip part down with:

function my(){  var b = document.getelementsbytagname("b")[3];  var str = b.tostring().replace(/[^0-9]/g, '');  //var x = str.parseint();  return str }  my(); 

it returns [object htmlelement]. how should proceed retrieve value, stripping except digits , replacing nothing , returning value? reading other posts of retrieving string , extracting integer got me trying these things out. know want do, not technical expertise getting done.

if

var b = document.getelementsbytagname("b")[3]; console.log(b) 

i <b>530 sek</b>. how come can't work it?

there 2 issues:

  1. use text content of dom element
  2. use global parseint function


1. have use text content of dom element:

var str = b.textcontent.replace(/[^0-9]/g, ''); 


2. parseint global function, not member function.

so instead of

var x = str.parseint();  

use

var x = parseint(str, 10);  

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -