Writing to HTML from External JS, Part II


#1

Following up on the original thread now automatically locked due to time elapsed (silly shame; too short a period!) at:

My code using

document.getElementById("someID").innerHTML = n;

wasn’t working right 'cause it was within a loop and the old value of n would keep getting written over by the new value when the intended outcome was to display all iterated values. Well, here’s the solution to that, actually:

document.getElementById("someID").innerHTML += n;

Instead of = I needed to use +=, as in n = n + 1 – that’s all!*

Now I had a very interesting discussion with the kind souls who helped me out in the old thread, learning how expensive DOM manipulation is and how totally ad hoc JavaScript still remains to some degree due to its evolutionary pedigree as an afterthought cobbled together in a relatively few days – but it turns out that the particular methodology I was attempting is actually valid and works to achieve the intended result!

So I’m just, I dunno, updating for the sake of posterity or something…just seems like a very important thing to note, that I only had trouble with getElementById() and innerHTML due to the iterative nature of my requirements (that is, I was using them within a loop), regardless of any “higher-level/big-picture” considerations of the approach!

However, I do wish to close by stressing again that I really learned a lot from all the “higher-level/big-picture” admonishments to adopt more modern less resource-intensive approaches so I am grateful anyway!

[*] Well, actually, because a loop is involved it turned out that I also needed to increment n twice in the code as well…but that’s a bit beside the point I’m making here.


#2

We see you trying some mechanism, but remain unclear about what it is you want to do. Is there a lesson related to this quiestion, and if so, would you be good enough to post the URL from the location bar in a reply?


#3

Well, first off, I’m sorry if I sounded accusatory…I tried to make sure to emphasize that the discussion in the old thread was truly deeply educational – and I’m honestly not just saying that!

But I like history and the amateur historian in me felt it of some minor importance that I follow up with an answer that most directly reflects the approach I was taking (again, not to disparage any of all the very fine and interesting advice from you and other kind souls)…now the problem isn’t from any Codecademy lesson, let me say now (sorry I didn’t make this clear before) – Codecademy lessons have actually been very clear to me so far, even though I don’t always find them terribly useful in a practical sense (hence, as I’ve said before elsewhere on these forums, I’ll “go Pro” once I learn me my basics so as to not waste time then) – but this exercise was partially self-constructed, running off of simple common beginners’ exercises (“print all even numbers between X and Y”) and making a mess of them with complications like printing to the browser window instead of the broswer console!


#4

[To further continue the discussion from How to Write into HTML From External JS File:]

WOW I HAD NO IDEA IT WAS THAT BAD…I don’t get it – Google Maps works just fine for me and that’s got to be the most used piece of JavaScript ever!!

I really don’t get it…if JavaScript’s so bad, how the heck are we getting streaming 4K video perfectly fine (excepting any connection issues, of course, which have nothing to do with JavaScript)…

Please explain. I’m really curious…and a bit scared now: even though I know JavaScript’s not going anywhere, I can’t believe I’ve “married into” such a Rube Goldberg-esque programming language!!

Speaking of which, how’s ECMAScript not JavaScript, as your cartoon seems to imply??

Geez, no wonder they make you learn all these damned frameworks and such!


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.