jquery - Only allow listener event to run if class exists in Javascript -
I have created a progress bar javascript object which updates a progress bar when a user is left In which the "click" "event listeners tied them. I just want to trigger these click-click events if they have a specific class attached, in this case" progress-bar-right "class I am in my code I'm unable to think of a way to do this. Here's my code:
Javascript object:
// progress bar var progress bar = function (element, startwall , And val, step, adlaves, ederets) {this.element = element; This.endVal = endVal; This.currentVal = startVal; This.step = step; This.addLefts = addLefts; This.addRights = addRights; Var self- This;} ProgressBar.prototype.initializeProgressBar = function () {jQuery (this.element) for the progress bar ({value: this.currentVal, max: this.endVal, step: this.step}); (var i = 0; i & lt; this.addLefts.length; I ++) {this.addLefts [i] .addEventListener ("Click", this.removeAmount.bind (this), Incorrect); } (Var i = 0; i & lt; this.addRights.length; i ++) {this.addRights [i] .addEventListener ("click", this.addAmount.bind (this), incorrect); }} ProgressBar.prototype.addAmount = function () {if (this.currentVal & lt; this.endVal) {this.currentVal + = this.step; This.update (); }} ProgressBar.prototype.removeAmount = function () {console.log (self); If (this.currentVal> 0) {this.currentVal - = this.step; This.update (); }} ProgressBar.prototype.update = function () {jQuery (this.element). Progress bar ({value: this.currentVal}); }
Javascript client code
// progress bar var addLefts = document.getElementsByClassName ("btn-lft"); Var addRights = document.getElementsByClassName ("BTN-Right"); Var progress progress = new progress ("# progress-time", 0, jQuery (". Signup-part"). Length, 1, adlifs, ederrates); ProgressBar.initializeProgressBar ();
So you can see that clicking 'Admile' and 'Exam' are the only ones to click on those who click on 'Adhil' and 'Adrites', if class "Progress Is there a way to include it in my code? Thank you
You can see that an element with the class exists in DOM in this way
if ($ ('progress-time-fine'). Length) {your code}
Comments
Post a Comment