0

I am trying to obtain the innerText of a 'TD' element by using jQuery's parents() and find().

allTitles = $("[href='/myLink/param?foo=1234']").parents("table:first").parents("table:first").find(".field_text");
name = allTitles[0].children[0].innerText;
console.log(name);

The code works fine in Chrome, but in Firefox the console prints out "null".

I did some debugging and the problem seems to be in the parents() function. While in Chrome I get all the attributes from the table elements, in Firefox it seems like the attributes are not being read and therefore resulting in "null" when we call find(".field_text").

Why does Chrome and Firefox behave differently event though I am using the same jQuery file?

RafaelCT
  • 85
  • 2
  • 6

2 Answers2

0

JavaScript is handled differently in browsers. It could be to do with with that. As you are already using jQuery, you could just carry on using it for your second query. Also if you are in control of your HTML, you can make your first query a lot simpler by adding a class to the second parant table:

var allTitles = $("[href='...']").closest(".your-class").find(".field_text");
var name = allTitles.children().first().text();
console.log(name);
DoubleA
  • 1,636
  • 14
  • 28
0

The problem was actually with children.innerText, it doesn't work with Firefox.

Just changed to children.textContent and it solved the problem.

Reference: children.innerText is not working in firefox

Community
  • 1
  • 1
RafaelCT
  • 85
  • 2
  • 6