Click here to Skip to main content
15,888,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am pulling data from a table with picture and Tooltip feature, but I am using javascript separately for picture, tooltip and text.

These are the sources of the data I received;

Table > .innerText
img > .src
img > .alt


The code I use for a single call is as follows.

const getData = (el, includeDuplicates = false) => {
  const getTag = [...el.getElementsByTagName('table')].map(asd =>
    asd.innerText 
  );
  return includeDuplicates ? getTag : [...new Set(getTag)];
};
getData(document, true);



When I do it according to the code above, it seems empty because I did not introduce the picture and tooltip parts in the table.



What do I need to do to get all the data in a table?

What I have tried:

There are a few methods I tried with ArrayList logic, but I could not get the result I wanted.
const getTag = [...el.getElementsByTagName('table')].map(asd =>
    asd.innerText 


The best thing I could do was edit this part like this.

const getTag = [...el.getElementsByTagName('table img')].map(asd =>
    asd.innerText + asd.alt 


With this addition logic, I got the results I wanted, but this time the table view is broken.

While pulling the table, I need to make the "img.alt" query for all the empty places so that it fills automatically. I need your help on how to do it.
Posted
Comments
Richard Deeming 6-Dec-22 4:23am    
Getting the inner text of a table doesn't really make much sense. Are you sure you didn't want the text of the table cells instead?
Ömer S. Doğru 2021 6-Dec-22 17:01pm    
I'm very new to Javascript so I couldn't understand the difference. Can you show a simple example to get table cell?

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