0

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

8
  • 1
    Your question is not clear. How to know that which column is for which kind of data ? You have already shown column header. Commented Sep 18, 2017 at 12:23
  • I just want to keep the header value along with column,e.g: in english column i want to show Test English and so on Commented Sep 18, 2017 at 12:25
  • so id column should have id 1, id 2 like that ? Commented Sep 18, 2017 at 12:26
  • id columns would have 1_id,2_id,3_id and so on. All i want to attach/append the text of header to columns. Commented Sep 18, 2017 at 12:27
  • Yes it can be like this id 1, id 2 @HimanshuUpadhyay Commented Sep 18, 2017 at 12:28

1 Answer 1

1

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);
            });
        });
Sign up to request clarification or add additional context in comments.

1 Comment

Hi @Khirad Banu, if you got your required solution with this answer, then can you please accept this answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.