Home > Enterprise >  Getting values of row in table using Javascript
Getting values of row in table using Javascript

Time:05-23

I'm trying to get information from a table I have populated into. I got this code :

> dataHtml  = `<tr onclick="getRowDetails(this)" class='accordion'
> id="accordion"> onclick="newAssign(this)"><td>${course.Year}</td><td>${course.Semester}</td><td>${course.Route}</td><td>${course.CourseName}</td></tr>`;

and once the row is clicked this function is triggered:

function getRowDetails(value) {
            console.log("showing this")
            console.log(value)
        }

and once I click on the row i see the following information: enter image description here

My question is how do I approach this if I want to show the value "Big Data" only?

thanks !!

CodePudding user response:

Like this:

      function getRowDetails(value) {
        /* for (let i = 0; i < e.children.length; i  ) {
          console.log(e.children[i].textContent);
        } */
        console.log(value.children[3].textContent);
      }

CodePudding user response:

var row = $(value); 
var text = '';
for (var i = 0, col; col = row.cells[i]; i  ) {
    if(col.innerHTML == 'Big Data')
        text = col.innerHTML;
          alert(text);
        }

the syntax may be wrong, i didn't try but i guess you can solve it like this.

  • Related