Beyond console.log, episode 2

Previously, on “Beyond console.log”

I will try in this article to give you some tips regarding the elements panel in DevTools.

Conventional wisdom says that a bad workman always has bad tools. But a good web developer will never use the Internet Explorer console, except to debug bugs specific to this browser, which is more reminiscent of Titanic than Queen Mary II.

Enough jokes.

Find an element's Event Listeners

Here's how devTools saved my day a while ago when a button called a function that was hidden somewhere in a few thousand lines of jQuery family code:

addcl1
Well, I admit, I took this screenshot on Facebook. And I doubt they use JQuery. Notice that the same function appears for each ancestor.

This will display the event listeners of the inspected element. I recommend checking the "Framework listeners" box, which was recently added to DevTools. This will allow you to access your function and not the framework's function (if you are using jQuery, for example).

Only, we can observe that there is a listener for each ancestor. We can fix this by unchecking the “ancestors” box:

much better!
much better!

Sometimes we want to know how and by which function an element is modified/deleted/changes attributes. That's what the “DOM breakpoints” menu is for.

addcl4

 When you have chosen which type of event to listen to, a blue dot appears:

addcl5

If you select the node, you will be able to see what types of events you have attached to it:

addcl6

Mastering Elements: Some CSS Tips

Halloween-Costumes-For-Programmers-_7
the drawing comes from the great blog “Stanley Colors“. Yours truly recommends that you read it. Similar to the oatmeal.

When a CSS rule has several selectors (separated by a comma), the selectors that correspond to the targeted element are displayed in black, and the others in gray. Moreover, if you pass the cursor over a selector, the elements affected by it will appear highlighted on the page.

addcl9

Inherited properties

You can also see which rules are inherited from parent elements: in inherited rules, you can see that inherited properties are displayed normally, while properties that are not passed down from parent to child, such as flex or display, s are displayed in gray:

addcl7

Calculated properties

Devtools sorts CSS rules by descending priority. This makes it fairly easy to understand why a rule isn't being applied. But sometimes, there are so many rules that it becomes difficult to find which one overridden the property you wanted to assign. It's like finding a needle in a haystack That's why you shouldn't hesitate to take a look at the "Computed" tab in the Styles panel. Here, there are no rules, just a list of the element's properties that have been modified by you, a framework, or the browser's styles.

Expand a property and you will see the list of rules that affect it. Clicking on the link takes you on a tour of the sources panel. If, on the contrary, you click on the arrow that appears when you hover the cursor, you will be taken to the styles tab of the elements panel, right in the right place.

addcl3

Last tip (which seems obvious to me, but you never know):

if you want an element to be styled as if it were hovered, you can click on “Toggle Element state” (“:hov” button in the styles tab):

addcl8

One more thing ...

Animations

Describing how the animation editor works would take too long, so I just show you an image:

2017-05-12 screenshot at 13.29.39

You can replay an animation, change offsets, each animated element has its own timeline… It's magic. Note that you can also edit the Bézier curves which determine the speed of a transition or animation:

addcl10
click on the curve-shaped button
addcl11
#canYouFeelTheMagic

That's it, I'll stop here. For real. Devtools also has a shadow editing tool for the box-shadow and text-shadow properties! Thank you for taking the time to read this, and please come back in a few days for episode 3.

Shadoks2

Julien, JS-Republican @JSRepublic
[actionbox color=”default” title=”” description=”JS-REPUBLIC is a service company specializing in JavaScript development. We are an approved training center. Find all our technical training on our partner site dedicated to Training” btn_label=”Our training” btn_link=”http://training.ux-republic.com” btn_color=”primary” btn_size=”big” btn_icon=”star” btn_external =”1″]