3 ms·
The second result is more semantically correct, but it will not function if called on tr.athing because tr.athing contains HTML elements that will be deleted wh
by mediumdeviation 5y ago
The second result is more semantically correct, but it will not function if called on tr.athing because tr.athing contains HTML elements that will be deleted when you replace the text. It is still much safer than innerHTML which will silently corrupt attributes. It's also interesting you need to prompt Codex for security best practices (and a bit questionable if it even "knows" anything about best practices)
I guess part of it is that a one-liner is impossible. Here's what I would write given the prompt
const makeUppercase = (id) => {
const element = document.getElementById(id);
if (element == null) return;
const makeChildNodeUpper = (node) => {
if (node.nodeType === Node.TEXT_NODE) {
node.nodeValue = node.nodeValue.toUpperCase();
} else {
node.childNodes.forEach(makeChildNodeUpper);
}
}
makeChildNodeUpper(element);
}
- IdiocyInAction 5y ago> It's also interesting you need to prompt Codex for security best practices Well, that's one of the central lessons of ML - garbage in, garbage out. There is a lot of garbage code out there and no easy a priori way to distinguish garbage code from good code.
- chrismorgan 5y agoHere’s a pretty good one-liner to make the text uppercase: document.getElementById(id).style.textTransform = 'uppercase';
- parhamn 5y agoThat was in their first comment.