Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I have one html table 'tab1'

XML
<table id="tab1">
               <tr>
                   <th>Empno</th>
                   <th>Ename</th>
                   <th>Salary</th>
               </tr>
               <tr>
                   <td>1</td>
                   <td>A</td>
                   <td>1000</td>
               </tr>
               <tr>
                   <td>1</td>
                   <td>A</td>
                   <td>1000</td>
               </tr>
               <tr>
                   <td>1</td>
                   <td>B</td>
                   <td>2000</td>
               </tr>
               <tr>
                   <td>2</td>
                   <td>C</td>
                   <td>3000</td>
               </tr>
               <tr>
                   <td>3</td>
                   <td>D</td>
                   <td>4000</td>
               </tr>
               <tr>
                   <td>3</td>
                   <td>A</td>
                   <td>1000</td>
               </tr>
           </table>


I want to check with every row first column. If more than one time with same data of that row first cell then want to make it as invisible false.
I tried but not able to achieve.

Can any one help me to complete this.
Posted
Comments
Sergey Alexandrovich Kryukov 2-Apr-15 0:39am    
If you asked question about HTML DOM manipulation, you are supposed to know HTML. If you know HTML, you can cope with HTML of your post. Right now, you don't show a table in your code, you show HTML with some characters escaped with HTML character entities. Please pay some attention to what you write yourself.

Now, What have you tried so far?

As you tagged "jQuery", you probably know what is that. So the answer would be: actually use jQuery, not just tag it. What's the problem?

Another question for you: why not preventing duplication of data in first place, when it is first populated?

—SA

Along with Sergy Alexandrovich Kryukov, if you are not using jquery
then try the following:
JavaScript
var tbl1=document.getElementById("tab1"); 
//alt 
var tbl1=document.querySelector("#tab1"); 

    for(var i=0;i<tbl1.rows.length;i++){>
      whatever_function(tbl1.rows[i].cells[0].innerHTML);
    }
 
Share this answer
 
Thanks everybody for your solutions
 
Share this answer
 
Please see my comment to the question. Actually use jQuery, not just tag it:
http://api.jquery.com/category/traversing.

Another idea: if you already know the structure (how many cells per row, first of all), you can simply take all the <td> elements and iterate through the set:
JavaScript
var allCells = $("td");
allCells.each(function(index){
   // do whatever you want,
   // using index and $(each)
})


Please see:
https://api.jquery.com/each,
not to be confused with https://api.jquery.com/jquery.each.

If you have more than one table on the page, use more complex selector. See for example: https://api.jquery.com/multiple-selector.

This is all really simple.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900