Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Perfect

Text displays when adding task via Chrome but not in Firefox. Why?

Subject = Question details (staying DRY).

Do you have a workspace we could view? Without something for us to look at, it's pretty much impossible to help you out.

Or copy/paste a code example.

2 Answers

Could be related to this issue with Firefox:

Firefox uses the property textContent instead of innerText.

For more information and a workaround, see this post on Treehouse: Firefox innerText undefined - Teacher's Note

Placid Rodrigues
Placid Rodrigues
12,630 Points

As mentioned in the Teacher's Note referenced by Van Wilson, we can solve the issue for firefox as follows:

if (typeof editButton.innerText === "undefined")  {
  editButton.textContent = "Edit";
} else {
  editButton.innerText = "Edit";
}

But there are multiple instances where we need to do the same checking. So to make it DRY, we can create two functions. Like this:

var setText = function(elementName, text) {
  if (typeof elementName.innerText === "undefined") {
    elementName.textContent = text;
  } else {
    elementName.innerText = text;
  } 
}
var getText = function(elementName) {
  if (typeof elementName.innerText === "undefined") {
    return elementName.textContent;
  } else {
    return elementName.innerText;
  }     
}

Then, when we need to set text of an element, we can do that in the following way:

setText(label, taskString);
setText(editButton, "Edit");
setText(deleteButton, "Delete");

And, when we need to get text of an element, we can do that in the following way:

getText(label);

As an example of getting text, in the editTask function, we needed to get the the text of the label's text and assign it to editInput.value. We can do it like this:

editInput.value = getText(label);

Hope that will help someone facing same issue.

Placid