0

I'm trying to display a table cell value to the console.log using JavaScript. I get a null value displayed to the console on any attempt. I believe the main issue is how I'm identifying the selector.

I have attempted to display the table cell value using a querySelector. I have attempted using the class and using the id. I'm guessing that I'm not using the correct selector, but I could use some guidance to ensure that the selector I'm using is correct. The class I attempted to use is oj-table-data-cell, and the id is mandatoryParts-table:partNumber_48_2.

  var dropDownValue = document.querySelector(".oj-table-data-cell select");

  console.log(dropDownValue.value);

The result I get in the console is null.

Both attempts using either the class or the id have resulted in null being displayed in the console. I did not use both class and id at the same time, just trying different ways to obtain the table cell value.

Here are some screenshots of the table display and the source code. Table Display

Source Code

jeppy7
  • 134
  • 1
  • 11
  • `:aria-label` ... nooooo – Roko C. Buljan Oct 28 '19 at 22:22
  • Your code seems to be targeting a ` – Moob Oct 28 '19 at 22:24
  • Hi Moob, that was one of the first things I tried. Any attempt to use .innerHTML or .value displays null in the console. I think I may be accessing the wrong selector. – jeppy7 Oct 28 '19 at 22:29
  • @jeppy7 than why you use `select` if a `select` element is not what you're interested in? – Roko C. Buljan Oct 28 '19 at 22:32
  • I do want to select, I just said that I tried your solutions prior to you mentioning it and it didn't work. I think the content may be pre-loading right now though. So I'm attempting to verify that. Just to be clear, I'm interested in getting the value of the cell either by using .innerHTML or .value. Anyway I can. – jeppy7 Oct 28 '19 at 23:26

1 Answers1

2

Try using the innerText property or

dropDownValue.innerText

Edit:

TextContent is better than innerText for several reasons listed below:

Difference between textContent vs innerText

Chris
  • 1,206
  • 2
  • 15
  • 35