Team did a lot of modification in a web application. Sometines I found jquery code like this one :
$('#foo').doSomething();
But when I'm searching for the id="foo"
in HTML, it does not exist anymore.
To help us and to prevent bugs, I want to console.log
every non-present elements forward to the $()
function.
Here is an example:
//I want to hide this text.
$('#foo').fadeOut(5000);
//This id #bar does not exist.
$('#bar').fadeOut(5000);
//I want to console.log that #bar does not exist
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="foobar">
I don't want to hide this text.
</div>
<div id="foo">
I want to hide this text.
</div>
<div id="bbar">
This layer is named bbar and not bar.
</div>
During dev, I want to log that #bar element called by $('#bar')
does not exist. Is it possible to extend jQuery? I want to output something like that:
Selector
#bbar
does not exist
Jquery version 3.1 is used. I read JQuery events on non present elements, but I don't want to change each call. I want to log non present elements, by extending jQuery for example.