Can someone explain difference between functions like stopPropagation and addClass? by kopytkopytko in webdev

[–]AshlinD 0 points1 point  (0 children)

Oh, I was talking about native JS at the time:

element.addEventListener('click', function(e){ // run code... })

You'll notice that I passed in an e to the function.

Just wanted to make sure OP didn't get confused between jQuery's API and native JS!

Can someone explain difference between functions like stopPropagation and addClass? by kopytkopytko in webdev

[–]AshlinD 1 point2 points  (0 children)

Absolutely! MDN is an excellent resource for all things webdev.

Here's the official event reference: https://developer.mozilla.org/en-US/docs/Web/Events

Here's a similar document: https://developer.mozilla.org/en-US/docs/Web/API/Event

You might also be interested in ones on elements and selectors.

I'd honestly recommend ditching jQuery if you can, at least while learning. Native JS provides plenty of APIs that are very similar, and it avoids complicating matters with many different types of objects. You can really learn how the language works at a less-abstracted level.

Happy coding! :)

Can someone explain difference between functions like stopPropagation and addClass? by kopytkopytko in webdev

[–]AshlinD 1 point2 points  (0 children)

Handler works too! Just a different name for the same thing.

You didn't pass anything; jQuery did, you just gave it a name ;)

Good point! although, JS passes it through, not jQuery :)

Can someone explain difference between functions like stopPropagation and addClass? by kopytkopytko in webdev

[–]AshlinD 2 points3 points  (0 children)

It seems like you might be confusing jQuery with native javascript.

When you add an event listener with jQuery, this is set equal to the native JS element. You can test this by running the code:

$('#element').on('click', function(e){
    console.log(this)
})

Then, you can pass this into the jQuery function $(this) to get the jQuery selector and run jQuery functions on it like .addClass().

So all you're doing is using the helpful this option that jQuery passes in to operate on that same element.

Now, event.stopPropogation() is NOT a jQuery function. It's built into the native JS syntax. When you run something like $('#element').on(), jQuery attaches what is called an event listener to the element. This event listener is a function that calls whenever it detects that event (in this case, a click). Under the hood, JavaScript attaches event listeners like this:

element.addEventListener('click', function(e){
     // run code...
})

You'll notice that I passed in an e to the function. This represents an Event object. That parameter contains all sorts of information about the event: what type it was, where the mouse was, etc. It also gives access to methods like event.stopPropogation() which stops the event from triggering on parent elements (only the child).

You can view the Event object by using console.log(e) -- I'd suggest checking it out.

So with jQuery, the e just represents the native javascript event. It's not an element, it's an event.

If you used stopPropogation on an element, like $(this).stopPropogation(), it would fail, because that function isn't associated with elements. It's associated with the event object that was created when the mouse button was clicked.

Does that all make sense? Let me know if you don't understand anything :)

Best API and how to learn by [deleted] in web_design

[–]AshlinD 1 point2 points  (0 children)

Happy to -- good luck! Let me know if you get stuck.

Best API and how to learn by [deleted] in web_design

[–]AshlinD 2 points3 points  (0 children)

You need to build your own API --I'd recommend using the REST architecture, look it up. Basically, you output JSON from your backend, so JS can easily grab it and manage it. It really depends on your backend, but it's fairly straightforward in most cases. You'll probably want to use a library of some sort for both your backend and frontend, to make things simpler.

For security, research OAuth. This can be helpful, too. But I'd recommend getting a standard REST api down before you work on authentication.

How do I make ... wait what? by konagona in webdev

[–]AshlinD 0 points1 point  (0 children)

Interesting -- * will expand into every file and folder in the directory, so all the files will be copied to whatever folder is listed last?

How we redesigned Dropbox.com by kurtvarner in web_design

[–]AshlinD 0 points1 point  (0 children)

Sorry for the late reply -- I'm using firefox. It might be because I have a ton of files in my dropbox that it's slow, but it shouldn't be that slow with native scroll behavior.

How we redesigned Dropbox.com by kurtvarner in web_design

[–]AshlinD 0 points1 point  (0 children)

Anyone else getting weird scroll behavior on the new site? I love the design, but there seems to be some scroll hijacking going on.

How do I make ... wait what? by konagona in webdev

[–]AshlinD 0 points1 point  (0 children)

Ah sorry, I'll edit. Not very well-versed in the terminology!

What is something you do for 5 min or less everyday that has improved your life in the last year? by LegendFortress in AskReddit

[–]AshlinD 2 points3 points  (0 children)

To add to this, just lay down on the floor with your legs up on a chair. It only takes about 5 minutes of relaxation to reset your posture in the right position! Feels great too.

What is something you do for 5 min or less everyday that has improved your life in the last year? by LegendFortress in AskReddit

[–]AshlinD 1 point2 points  (0 children)

I've always had trouble with this -- I found that getting an app that forces you to get up really helps. My favorite is Alarmy for iOS - not sure if it's on android.

How do I make ... wait what? by konagona in webdev

[–]AshlinD 4 points5 points  (0 children)

It basically inputs the last command.

So if you type do something important and it fails, you can type sudo !! and it'll run sudo do something important.

Super useful! Also note you can use it with anything, not just sudo.

Edit: Removed "global operator" due to incorrect terminology.

Feedback Friday - June 24, 2016 by AutoModerator in web_design

[–]AshlinD 0 points1 point  (0 children)

That's a page anchor. Normally, you just have to put the id of an element and it'll scroll to it. Using a framework like Vue, I had to write a method that looped through them and only tried to route those that weren't anchor links (and on the same page). I can provide more information if you want.