
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
jquery.waitforChild
Advanced tools
jQuery plugin to declare handlers to be executed once a child node is appended to the target element
Operate on matching children of a given element. If no matching children are found, it will set an observer to run the desired operation once (if) the element gets inserted afterwards.
Let's say you have a container and this container has children
<ul id="mylist">
<li class="first">First item</li>
<li class="second">Second item</li>
<li class="third">Third item</li>
</ul>
It's trivial to traverse the children to add an extra class, let's say "pink".
$('#mylist').find('li').addClass('pink');
And if you wanted to operate only on the element that has the className "second" this is trivial too
$('#mylist').find('li.second').addClass('pink');
But what would happen if you wanted to set handlers, or perform DOM manipulation on elements that doesn't yet exist? Let's say you have the empty container:
<ul id="mylist">
</ul>
And you know that, eventually, another function, handler or event will append the list elements
$('#mylist').append('<li class="first">First item</li>');
$('#mylist').append('<li class="second">Second item</li>');
$('#mylist').append('<li class="third">Third item</li>');
But you don't know when or from where. With jquery.waitforChild you just can set a listener on the container:
$('#mylist').waitforChild({
onFound: function(child) {
child.addClass('pink');
},
querySelector: 'li.second'
});
Now, whenever a matching childNode is inserted on #mylist, the function will be invoked on it.
There are some cases in which you will want to act on the first element to match the selection, so further elements won't trigger
the handler function. In that case, pass the option once
to the config object:
$('#mylist').waitforChild({
onFound: function(child) {
child.addClass('pink');
},
querySelector: 'li.second',
once: true
});
Which will operate only on the first matching element ever appended to the container.
The plugin returns the original element, so you are free to chain methods as with other jQuery functions
$('#mylist').waitforChild({
onFound: function(child) {
child.addClass('pink');
},
querySelector: 'li.second',
once: true
}).addClass('niceclass');
Delegation is useful if you want to take advantage of natural event bubbling, and if you're already using jQuery you'll be able to use it even in older browsers. However, there are cases in which delegation won't solve your problem. For example, when you want to apply KnockOut's declarative bindings, or render a Backbone View.
Moreover, abusing event delegation makes it harder to keep track of where is a given behavior triggered, and you risk assigning it multiple times if you declare the delegated event in the wrong place.
The MutationObserver object needs an existing Node to operate on. Therefore, you can't invoke jquery.waitforChild on an element which isn't in the DOM.
Also, older browsers don't support this feature. Pay a visit to Can I Use to check if your browser is supported.
FAQs
jQuery plugin to declare handlers to be executed once a child node is appended to the target element
We found that jquery.waitforChild demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.