When you click, how do you know which elements were blurred?

I’m building a drag drop page builder with jQuery and I faced this problem: I need to know when I click on a particular element, which element was blurred? Sounds easy, isn’t it? For example, there are two divs, A and B on the page. When I click on B, I want to know if right before that, A was focused. I don’t know if this make any sense to you but hopefully, it does. I thought it was impossible… Luckily, I found a solution and my editor is working as expected now.

The idea

In order to make this possible, the divs we want to check must have class attribute. Then in every click on the document, we will record the classes of elements that were clicked in a string (I will use localStorage). The problem is, how can you record the classes of elements that were clicked? This code does the trick:

In this case, the element I want to check later if it was blurred is vgt_actual_html_element.
If in the string that store all the class name of the elements that were clicked there is vgt_actual_html_element.

In the next click, when we check if the localStorage varialbe vgt_actual_html_get_clicked has the value no, that means our vgt_actual_html_element was blurred.

I hope that wasn’t too hard to understand.