Perhaps the issue with that though is that you are assuming a grater level of knowledge than I actually possess currently, unfortunately JavaScript isn’t something I covered extensively in college so I have only the most basic of knowledge / understanding of the language, so much so it's probably better to just assume that I have no idea what you are talking about because the chances are I probably don't.
Unless you don't know how to use a search engine and/or documentation resources like MDN and MSDN I don't think I am assuming much of anything in particular. That fact that you figured it out based on the information I provided doesn't really seem to question that assumption.
i know its maybe not the best way but at least it is something that i sort of understand i can follow what its doing unlike that ternary operator stuff the logic of which isn't making a whole lot of sense to me.
The ternary operator is just a different way of writing if/else.
Code: Select all
if condition == true then
doSomething();
else
doSomethingElse();
end
// or in ternary form
condition ? doSomething() : doSomethingElse()
It's a personal choice and value judgment about legibility.
I mean maybe this is simply another case of me missing something that is obvious to those that are more knowledgable about this stuff but I'm not really seeing how using that ternary operator stuff would actually accomplish what I'm trying to do since this isn't one of them times when i need to use an if() or a boolean (true or false)
I simply need to get the value from the parent row and then apply it to the children of that row so that i don't get the id is null error when i hover on the TDs.
You might want to actually
try the working code I provided so that you can figure out why it works instead of assuming it doesn't because it doesn't fit your preconceived notions. That's on line #511.
I'll add this:
https://stackoverflow.com/help/how-to-ask
In particular this:
https://stackoverflow.com/help/mcve
Your last example was the first to include a not exactly minimal testcase, but a working testcase nonetheless. As far as the JS went it was close enough to minimal. Therefore I was able to post a working solution in seconds. That's the way to go. One thing I personally find is that trying to distill a problem to a minimal testcase will clarify it to yourself and often provide the solution in the process.
You'll note a common thread in the answers you received. I was talking in relative generalities because you posted disconnected code snippets. You can see the same in the first comment to this topic:
jscher2000 wrote:I can't test this without creating a document, but as a general idea:
Since you didn't pick up on my subtler hint when I said I would propose the exact opposite solution, to put it more bluntly your question as phrased is not a great question.
I simply need to get the value from the parent row and then apply it to the children of that row
This part is probably okay: "I simply need to get the value from the parent row"
But this part presupposes a solution: "then apply it to the children of that row"
When you lay out a problem you should indicate what the problem is, what you're trying to achieve and what you've already tried. Regarding your complaint, part of the reason you received answers in generalities is because you didn't provide a working testcase until the last reply. Ideally it would be a
minimal testcase, but the JS was close enough in any case, which enabled me to provide a working solution in seconds. One that you then dismissed as not working because it didn't fit your preconceived notion of how the problem should be solved. Most people don't even bother responding to questions like that precisely for that reason, but I'm an optimist.
Question since I'm already getting the event target and the data attribute of that target would a simple loop work for this purpose, something like this perhaps ?
As for that code snippet, something along those lines would work but it doesn't make a whole lot of sense to do it on each and every hover event. You'd want to do it during setup, e.g., on DOMContentLoaded. That's an event, so document.addEventListener('DOMContentLoaded', SomeInitFunction).
Code: Select all
var trs = getElementsByTagName('tr') //or querySelectorAll())
// for loop over trs
var tr = trs[i]
var tds = tr.getElementsByTagName('td')
// for loop over tds
tds[j].setAttribute(whatever, tr.getAttribute(whatever))
That's the way to write it backward compatible to possibly IE5, but at least IE6. On modern browsers you could also use array.forEach() to write it more elegantly.
https://developer.mozilla.org/en-US/doc ... ay/forEach
PS Props for learning proper JS instead of doing jQuery and subsequently not having a notion of what JS actually entails!
Intelligent alien life does exist, otherwise they would have contacted us.