1

I have this code:

<table id="ts_res_tbl" class="vToolsDataTable"> 
<thead> 
<tr> 
<th class="sortable">Number</th> 
</th> 
</tr> 
</thead> 
<tbody>
<tr class="vToolsDataTableRow2"><td class="num"><a>574</a><div>...
<tr class="vToolsDataTableRow2"><td class="num"><a>575</a><div>...
<tr class="vToolsDataTableRow2"><td class="num"><a>576</a><div>... 

thousands values...

I need to select a tr which has '575' text, how can I do this using Javascript? JQuery I will not use!

And after the selector is chosen, I will have the following code:

<tr class="vToolsDataTableRow">
  <td class="num">
    <a>072 П</a>
      <div></div>
  </td>
  <td class="stations">Text 1<br>Text</td>
  <td class="date">
    <div>Text <span>Text, 28.10.2014</span></div>
    <p class="clear"></p>
    <div>Text<span>Text, 29.10.2014</span></div>
    <p class="clear"></p>
  </td>
  <td class="time">19:27<br>05:58</td>
  <td class="dur">10:31</td>
  <td class="place">
    <div title="Text">
        <i class="" style="margin-left: 0px;">X</i>

And then I need to find one letter "X" between tag, how it can be done?

Eric Carlton
  • 27
  • 1
  • 4
  • jQuery is JavaScript (though I suspect you mean that you simply don't want to use that library?). But...what relation does the end-result have to the search string? – David Thomas Oct 27 '14 at 10:04

1 Answers1

0
<style type="text/css">
    tr.selected {
        background-color: #F00;
    }

</style>
<script type="text/javascript">

    function search(table, value) {
        var Rows = table.getElementsByClassName('vToolsDataTableRow2');

        for(var i = 0; i < Rows.length; i++) {
            var N = Rows[i].getElementsByClassName('num');
            if(N.length == 0) continue;


            var A = N[0].getElementsByTagName('a');
            if(A.length == 0) continue;

            var v = A[0].innerHTML;

            if(v.toString() == value.toString()) {
                Rows[i].className = 'vToolsDataTableRow2 selected';
            }
            else
            {
                Rows[i].className = 'vToolsDataTableRow2';
            }
        }
    }

    search(document.getElementById('ts_res_tbl'), 575); 

</script>
John V
  • 875
  • 6
  • 12