It would be beneficial to people still learning to remove any loaded content such as "You might be able to get it to work with PHP templates, but I'd say this method is best for JavaScript" - You can absolutely and 100% do this with PHP with great ease, and other languages like Ruby, .Net etc etc etc - Remember they've been around longer and more mature so can handle this stuff in their sleep, we do it every single day, and it is in fact easier as those languages have less boilerplate than React/Vue/etc.
I hear you, I don't think I explained my reasoning very well there!
You're right, you can definitely get this working with PHP and any other language using templates. The reason I prefer to use JS is
Control over styles isn't limited to the backend - you could make a button add/remove a class, for example, which takes longer to do with inline JS.
You can keep everything (JS, HTML, CSS) in one area. I know you could just make a tag in PHP, but that JS would be in the global scope without taking extra steps and (to me) it feels a little clunky.
With that said, I can already see holes in my arguments - at this point it's more to do with my personal preference/experience. I do encourage working like this in non-JS environments, but I'm not an expert in that area!
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Good article, with some nice examples!
It would be beneficial to people still learning to remove any loaded content such as "You might be able to get it to work with PHP templates, but I'd say this method is best for JavaScript" - You can absolutely and 100% do this with PHP with great ease, and other languages like Ruby, .Net etc etc etc - Remember they've been around longer and more mature so can handle this stuff in their sleep, we do it every single day, and it is in fact easier as those languages have less boilerplate than React/Vue/etc.
I hear you, I don't think I explained my reasoning very well there!
You're right, you can definitely get this working with PHP and any other language using templates. The reason I prefer to use JS is
With that said, I can already see holes in my arguments - at this point it's more to do with my personal preference/experience. I do encourage working like this in non-JS environments, but I'm not an expert in that area!