I Can JavaScripting?
1001 words. Time to Read: About 10 minutes.Hey! Sorry for the long gap. It’s been over a month since my last post, which is not ok. Luckily, I’ve recently started the 100 days of code challenge along with a number of the other CodeNewbies, and that should help keep me on track. Also, I’m working on some changes to the blog that should be coming up here in the next week or so. I actually got a url that means something, which is neat! More on that after the change.
Anyways, I have been having a whole lot of success in the JavaScript world recently, and I wanted to share some of the wisdom nuggets that I’ve stumbled upon. First thing’s first. If you haven’t heard of the JavaScript30, it is a 30 day (or so) challenge wherin Wes Bos, a genius person and excellent teacher, works through 30 different projects with you using only Vanilla Javascript. This is especially great if you are like me and have a slight distrust of just installing a random library without vetting it out, which makes doing anything exhausting. A lot of times I end up starting something, finding out lots of people use a library for it, trying to do it without the library, getting stuck, and giving up. This is especially frustrating, because I feel like I know JavaScript, but can’t actually do anything with it! Not anymore! I want to share a few of the most useful things with you that use Vanilla JavaScript and not libraries. (Note: I don’t hate libraries. I just think there is something to be said for not having to manage dependencies.) So here we go.
Just Selecting Stuff
The very first useful thing you should know is how to get at (or create) things in the DOM. This is something that JQuery makes really easy, but here’s how to do it the rugged way.
Making Things Happen (Events)
I hinted at this in the previous section. What if you want to run some magic voodoo everytime someone mouses over your title or everytime someone submits a form? It’s really that simple.
And that’s it! Now, the first time the user mouses over the title, its font will grow to 48px. Note that you would have to listen for a mouseleave
event and pass in a different function if you wanted it to shrink back to normal once the user mouses out of the title.
Modifying Elements
The last thing I’ll talk about are some common ways to modify elements using JavaScript.
A lot of times, it is the easiest to simply toggle a class and handle all of the excess animations, changes, styling in the css. Makes things easier to read and find.
Anyways, that’s it for now. More coming soon!
Author: Ryan Palo | Tags: javascript | Buy me a coffee
Like my stuff? Have questions or feedback for me? Want to mentor me or get my help with something? Get in touch! To stay updated, subscribe via RSS