Your production scripts are safe with us


👋,

⚠️ This weekend, Slater experienced an outage. While we make every effort to ensure Slater's uninterrupted operation, occasional server issues may arise. But! The key takeaway from this weekend's incident is that the production scripts on your clients' websites remain unaffected even if a Slater outage occurs. Slater scripts are exceptionally resilient and you can trust Slater to provide Javascript functionality on your client websites.


Our in-house Javascript and Surf guru, Witt, re-recorded a getting started video. If you haven't synced up Slater with Webflow yet, please watch and give Slater a go.

Everyone at Edgar Allan loves Witt's how-to videos. We want to do more of them. What subject matter would you like him to cover?


JavaScript 101: More DOM Traversal

Last week, we learned about the DOM (Document Object Model) and how we can get started navigating or "traversing" the DOM. This week, let's dig deeper into this concept with "this". When interacting with the DOM, like when a user clicks or mouses over an elment, "this" refers to the element that the event happened to.

For example, let's say you have a button on a webpage. If you attach a click event listener to the button, "this" inside the event handler (the function that runs when the event happens) will refer to the button that was clicked. Let's see this in action:

document.querySelector('button').addEventListener('click', function() { 
  console.log(this); 
});

Here, when you click the button, `this` will be printed out to the console, and `this` will be pointing to the button that was clicked.

This can be super handy when you want to move from the element that triggered an event to a nearby element. Imagine you have a list of items, and each one has a delete button. When a delete button is clicked, you want to remove that item from the list.

let deleteButtons = document.querySelectorAll('.delete-button');
for (var i = 0; i < deleteButtons.length; i++) { 
  deleteButtons[i].addEventListener('click', function() {
     this.parentNode.remove(); 
  }); 
}

In this example, when a delete button gets clicked, the function runs. Inside the function, "this" refers to the delete button that was clicked. `this.parentNode` is the parent element of the delete button, which would be the item in the list. The `.remove()` method gets rid of the item from the DOM.

Now, let's talk about how this works in jQuery, a JavaScript library that is bundled with Webflow and makes DOM traversal a lot simpler. With jQuery, "this" works the same way. Here's how you'd write the previous example using jQuery:

$('.delete-button').click(function() {
  $(this).parent().remove();
});

In this jQuery example, `$(this).parent()` selects the parent of the delete button that was clicked, and `.remove()` gets rid of it from the DOM.

"this" is a really powerful tool in JavaScript that makes traversing the DOM a whole lot easier. It lets you refer to the element that triggered an event, and from there, you can move to other elements nearby.

Go try to use "this" in one of your Webflow projects and let us know how it goes!

Happy coding!

🤙 The Slater team


🙏 If Slater helps you create better websites, please support the team behind it.



1295 Canyon View Rd, Midway, UT 84049
Unsubscribe · Preferences

Welcome To Slater!

Slater resources, updates and community activity

Read more from Welcome To Slater!
photo

Do you get confused when undoing (cmd + z) in Slater? We auto-format your code on save. The auto-formatting updates your code, and those updates get pushed into the undo stack. You can now improve your workflow by formatting the code when you choose—not just on save. To gain more control over when your code formats: Turn off auto-format code in the Code Editor Settings Use cmd + shift + f to format your code We added a handful of other improvements: Console logs and debuggers are now...

video preview

Last week, we announced that CSS updates were on the way—and now they're here! You can now generate CSS files just as quickly and easily as JS files. In the video below, we give a quick demo of the new functionality. If you have a Smart Script loaded in your project, you can instantly add CSS. In the demo, we also show how to add CSS in the Webflow designer. Give it a try and let us know what you're building! Community Library 🖍️ Text Highlight ColorCSS code for custom text selection. 🅰...

Do you use Slater for CSS? CSS support in Slater has always been somewhat of an afterthought—JavaScript is our love language! But sometimes, you need a simple way to add CSS to your project. Maybe you want to write a complex grid or use a CSS property that Webflow doesn't support. That's why we've decided to make CSS a first-class citizen. We considered launching the new CSS functionality today, but we want to test it a bit more. Expect it early next week. To prepare for the launch, let's...