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 trialRyan Taylor
38,343 PointsText displays when adding task via Chrome but not in Firefox. Why?
Subject = Question details (staying DRY).
2 Answers
Van Wilson
11,806 PointsCould 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
12,630 PointsAs 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
Alex Friant
6,444 PointsAlex Friant
6,444 PointsDo 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.