'Equivalent of attaching a listener to buttons on document ready in jQuery instead of vanilla JavaScript?
How do I convert this JavaScript code to jQuery code?
if (document.readyState == 'loading') {
document.addEventListener('DOMContentLoaded', ready)
} else {
ready()
}
function ready() {
var removeCartItemButtons = document.getElementsByClassName('btn-danger')
for (var i = 0; i < removeCartItemButtons.length; i++) {
var button = removeCartItemButtons[i]
button.addEventListener('click', removeCartItem)
}
}
Solution 1:[1]
jQuery is a library of Javascript, and therefore nothing needs to be converted.
Solution 2:[2]
If you are an Android application developer you should not be investing effort here as JVM(ART or Dalvik) takes care of all security related to execution of loaded classes moreover I have never heard of any hack / expolit in Android that enables executing of code java that was not packaged with the APK.
Note JS code and its vulnerabilities are something completely different than running Java class in JVM.
If you are instead working on Android OEM platform / firmware code then you ca refer to Android guidelines on class loaders here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Stephen Ostermiller |
| Solution 2 | Taranmeet Singh |
