- Joined
- Oct 19, 2023
UNORGANIZED RANT INCOMING BECAUSE THIS WAS JUST THAT NIGGERLICIOUSYeah, the more I work on javascript the more niggerlicious it seems.
Is it bad practice to use an anchor element to change inner.html
for example
JavaScript:let niggerlicious = document.getElementById("about-us-anchor"); niggerlicious.onClick = myFunction let divineProvidence = document.getElementById("container-div"); function myFunction(){ divineProvidence.innerHTML = "html here" }
I'm just making a basic website template for my portfolio. I was thinking a basic landing page for a business can be really simplified by just using javascript to change the html of the page instead of redirecting you to another webpage that looks practically fucking identical.
Think about what you're doing. You might be creating an absolute CURRENT YEAR WEB2.0.34532.7b.alpha.commit4af2b6ee.niggerfaggot.prod-1.retardedversionstring-20240521.patch2-1 JavaScript soydev usability nightmare right here. Always be extremely careful with JavaScript and never use it more than absolutely necessary. Look into generating all of your redundant HTML on the server side instead of shitting it onto the client for no fucking reason. I've heard Hugo is good for that, I've never used it though. You could also use this as an excuse to learn PHP or something, which means you get to have fun making shit run on the server. You could even make your own forum! And if you do it right, it wouldn't require JS for almost all of its functionality.
I don't think the anchor tag being for things like that is too bad, though. The anchor tag is used for navigation, and overriding it with JS without a JS-free option is fucking retarded but it's still a thing that commonly happens. If I was doing some niggerlicious dynamically-loading modern webapp shit, I would somehow make it simultaneously work with JS enabled and disabled, which is very possible and requires a bit of extra server API. You can do that by setting the href attribute but also having an event handler that does whatever AJAX bullshit but then suppresses the default behavior of navigating to the link. Obviously it also needs to properly handle URLs for permalinking and use the History API to make the back/forward buttons in browsers work right. You're doing that, right? Because if you use JS for navigation you have to be very careful or you will make a niggerlicious shitapp with a broken back button and no permanent links. Nobody likes that.
Summary: At least you aren't also using a JS framework on top of everything else. Don't worry, you'll figure it out some day: Using JavaScript in the first place is a mistake 99% of the time. It's really good for that 1%, don't get me wrong, but this isn't that 1%.
Also, maybe this is just an example instead of something you would actually do in real life. If so, only the following criticism is valid:
It is absolutely super niggerlicious to use element.innerHTML. Setting that property causes the browser to parse the element again as HTML and set up the DOM nodes again, and it gets worse when there are tons of extra nodes in there. It even fucks up event listeners too. It's probably fine in this case because you're actually changing the entire page instead of 1 element, but be very careful with innerHTML. Always try to create DOM nodes entirely with JS and add them as children of another DOM node instead of setting innerHTML for that node and causing retarded shit to happen for no good reason.