Khirad Zahra
Khirad Zahra

Reputation: 893

Assign the value of table header to corresponding columns using jquery

Is it possible to assign the value/text of header column to its corresponding data column records using jQuery/JavaScript?

Like id columns should have id header value,and English columns should have English header value etc.

enter image description here

Upvotes: 0

Views: 171

Answers (1)

Himanshu Upadhyay
Himanshu Upadhyay

Reputation: 6565

this is your solution:

       $(document).ready(function(){
            $('tr').find('td').each(function(i){
                var ind = $(this).index();
                var text = $(this).text();
                var header_text = $('thead > tr').find('th:eq('+ind+')').text();
                $(this).text(header_text+': '+text);
            });
        });

Upvotes: 1

Related Questions