javascript - jQuery - Click link based on css class and name of link -


is possible have jquery find text of object , find link before , click it? have example want jquery click on either of 2 links below:

<tr>     <td nowrap="true" width="170" valign="top">          <div class="float-left"> <b><a href="javascript:gotoeturl('/url-example-1.html','business');">1234 account</a></b> <br> <span style="display:none" class="fullaccnum">1234</span>          </div>     </td> </tr>  <tr>     <td nowrap="true" width="170" valign="top">         <div class="float-left"> <b><a href="javascript:gotoeturl('/url-example-2.html','business');">5678 account</a></b> <br> <span style="display:none" class="fullaccnum">5678</span>         </div>     </td> </tr> 

here jquery i'm using , works happens if order of accounts above gets sorted differently click on wrong link wrong account:

if(account_id == '1234'){     jquery(".float-left b a")[0].click(); //click on first href } else {     jquery(".float-left b a")[1].click(); //click on second href } 

so possible jquery this:

if(account_id == '1234'){     //find span class='fullaccnum' span equals 1234     //found match, go tree , click href     jquery(".float-left b a").click();     //goes 'url-example-1.html' } else {     //find span class='fullaccnum' span equals 5678     //found match, go tree , click href     jquery(".float-left b a").click();     //goes '/url-example-2.html' } 

try use function

 function clickonanchor(text){        $('tr').each(function(){           var spantext = $(this).find('.fullaccnum').text();           if (spantext == text){                $(this).find('.float-left > b > a').click();           }        });         } 

and use it

clickonanchor('1234');