How to access element in html code

186 Views Asked by At

1-What code i write to get all "want to access" element in this code no other element like "some data" and only want elements with in div class bestMFdtl2.

2-and if i want some specific element with in this code according to choice how to do this, i am using html jerico parser.Please help me and those have problem reading code i am sorry for this but you are programmer i thought you like this.

3-How to get href link from the tags.

<div class='bestMFdtl2 '>
        <div class='tBrd btBrd tbg'>
         <div class='FL eqTle2 wd_182 rtBrd PL10 PR10'><a href='' class='bl_11'><strong></strong></a></div>
       <div class='FL eqTle wd_65 rtBrd PL5 PR5' align='center'><strong>some data</strong></div>
     <div class='FL eqTle wd_83 rtBrd' align='center'>
 <div class='btBrd'><strong>some data</strong> <span style='font-size:8px;'>some data</span></div>
        <div class='PT3'>some data</div>
        </div>
  <div class='FL eqTle wd_46 rtBrd btBrd' align='center'><strong>some data</strong></div>
    <div class='FL eqTle rtBrd'>
   <div align='center' class='btBrd'><strong>some data</strong></div>
    <table width='100%' border='0' cellspacing='0' cellpadding='0'>
        <tr>
       <td align='center' width='56' height='20' class='rtBrd'><strong>some data <sup>some data</sup></strong></td>
       <td align='center' width='56' class='rtBrd'><strong>some data <sup>&nbsp;</sup></strong></td>
        <td align='center' width='56' class='rtBrd'><strong>some data <sup>&nbsp;</sup></strong></td>
        <td align='center' width='56' class='rtBrd'><strong>some data<sup>&nbsp;</sup></strong></td>
        <td align='center' width='56' class='rtBrd'><strong>some data<sup>*</sup></strong></td>
        <td align='center' width='56'><strong>some data <sup>*</sup></strong></td>
        </tr>
        </table>
        </div>
        <div class='FL btBrd' style='width:43px;'></div>
        <div class='CL'></div>
        </div>
        <div class='equityN2'>
        <table cellspacing='0' cellpadding='0' style='margin-top:5px;'><tr>
        <td width='185'><div align='left'><a class='b-12' title='BNP Paribas Equity Fund (G)' href=''>Want to access</a> </div></td>
        <td width='70' nowrap=''><a href='' class='dgrey_12' target='_blank'>Rank 1</a><br><a href='/mf/crisil_methodology/' target='_blank'><span class='star'></span><span class='star'></span><span class='star'></span><span class='star'></span><span class='star'></span></a></td>
       <td width='70' style='text-align:right;'>127.22</td>
         <td width='40' style='text-align:right;'>42.03</td>
         <td class='#000000' width='48' style='text-align:right;'>--</td>
        <td class='grn' width='48' style='text-align:right;'>3.0</td>
        <td class='grn' width='48' style='text-align:right;'>10.3</td>
        <td class='grn' width='48' style='text-align:right;'>6.6</td>
         <td class='grn' width='50' style='text-align:right;'>18.9</td>
         <td class='grn' width='50' style='text-align:right;'>5.6</td>
        <td><A href='want to access' title='Download Form' target='_new' class='mfToolt'><img src='' alt=''></A></td>
         </tr><tr>
        <td width='185'><div align='left'><a class='b-12' title='' href='/'>want to access</a> </div></td>
        <td width='70' nowrap=''><a href='' class='dgrey_12' target='_blank'>Rank 1</a><br><a href='/mf/crisil_methodology/' target='_blank'><span class='star'></span><span class='star'></span><span class='star'></span><span class='star'></span><span class='star'></span></a></td>
        <td width='70' style='text-align:right;'>105.26</td>
        <td width='40' style='text-align:right;'>12.37</td>
        <td class='grn' width='48' style='text-align:right;'>0.7</td>
        <td class='grn' width='48' style='text-align:right;'>3.1</td>
        <td class='grn' width='48' style='text-align:right;'>8.8</td>
         <td class='grn' width='48' style='text-align:right;'>3.6</td>
        <td class='grn' width='50' style='text-align:right;'>16.1</td>
        <td class='grn' width='50' style='text-align:right;'>5.8</td>
        <td><A href='want to access' title='Download Form' target='_new' class='mfToolt'><img src='' alt=''></A></td>
        </tr>

1

There are 1 best solutions below

1
On

Given the comments, I believe this is what you're after.

var x = document.getElementsByClassName("bestMFdt12");

for (var i = 0; i < x.length; i++){
    var x2 = x[i].getElementsByClassName("b-12");

    for (var j = 0; j < x2.length; j++) {
        //Do something with the elements, access them with "x2[j]", these loops will go through every element within both classes and allow you to process them

        //Example:
        var current = x2[j];
    }
}

This should, get an array of all the "bestMFdt12" elements, and for each one of those search inside for any "b-12" elements. Where I've put the example, you can add the code to process these elements.