<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Melih Korkmaz on Medium]]></title>
        <description><![CDATA[Stories by Melih Korkmaz on Medium]]></description>
        <link>https://medium.com/@melihkorkmaz?source=rss-b27d90815517------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*tYKJ8UIl2GdpZ3PB.</url>
            <title>Stories by Melih Korkmaz on Medium</title>
            <link>https://medium.com/@melihkorkmaz?source=rss-b27d90815517------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 05:55:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@melihkorkmaz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Event Bubbling in Javascript]]></title>
            <link>https://medium.com/@melihkorkmaz/event-bubbling-in-javascript-d89137bd56c4?source=rss-b27d90815517------2</link>
            <guid isPermaLink="false">https://medium.com/p/d89137bd56c4</guid>
            <category><![CDATA[events]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Melih Korkmaz]]></dc:creator>
            <pubDate>Fri, 13 Jul 2018 05:14:30 GMT</pubDate>
            <atom:updated>2018-07-13T05:14:30.890Z</atom:updated>
            <content:encoded><![CDATA[<p>Using nested events in javascript can be difficult to understand. At the beginning of my javascript dev career, I never understood when a dom event might be fired or what the order is for nested events. After I learned event bubbling it began more easy to use.</p><p>Imagine that you have three nested divs, one button inside the inner div and all tags have a click event as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afd220ffecbe82f57343523b1119e144/href">https://medium.com/media/afd220ffecbe82f57343523b1119e144/href</a></iframe><p>I added the same function as click event for all elements but of course, you can use different functions for each.</p><p>I’ve also created some CSS classes to look fancy and added padding them to click easily each element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u3IzXjYOzCh0h9V3VFUvmg.png" /></figure><p>And my javascript code looks like;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/762cabf379c8a5cfcc430d3cb127632b/href">https://medium.com/media/762cabf379c8a5cfcc430d3cb127632b/href</a></iframe><p>As you see when you click a div container, you should see console log message.</p><p>Ok, in this case, if you click between “red” border and “blue” border, that means you click outer div. And you should see “Red Div Clicked!” message.</p><p>But if you click the area between “blue” border and “green” border, that means you click blue div and red div at the same time. So you should see;</p><p>“Blue Div Clicked!” then “Red Div Clicked”.</p><p>It’s the same for the button. When you click the button, you also click blue, red and green div right?</p><p>And console log order never changes. You always see this message;</p><pre>&quot;Button Clicked!&quot;</pre><pre>&quot;Green Div Clicked!&quot;</pre><pre>&quot;Blue Div Clicked!&quot;</pre><pre>&quot;Red Div Clicked!&quot;</pre><p>You see that it starts from inner content and goes to outer content. So you can imagine this like an expanding bubble. That’s why its name is event bubbling.</p><p>For some cases, you might need the cut of the expanding. For doing this, you should get the “click event” object and use event.stopPropagation() method.</p><p>For the same code;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b483dce0e8311b5b502fb29e52edfda/href">https://medium.com/media/4b483dce0e8311b5b502fb29e52edfda/href</a></iframe><p>In this case, if you click “button”, you should only see “Button Clicked!” message in the console. Upper events will not be fired. So that’s how you can control your event bubbling flow.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d89137bd56c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>