I
I
Ilia V. Soldatkin2019-09-29 00:05:39
JavaScript
Ilia V. Soldatkin, 2019-09-29 00:05:39

How to remove the class of only one element from several?

We have:

$('body').on('click', '.js-btnDelete', function() {
    $(this).parent().remove();

    $('button').removeClass('active');
  });


That is, we click on the element with .js-btnDelete and remove the .active class from all buttons.
Question: How to make it so that it is removed only from one specific button?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2018-05-30
@rockon404

At least like this:

function Modal(options) {
  this.el = (options && options.el) || document.body;
  // init some options (text, width, onClose, onConfirm, etc)
  this.init();
}

Modal.prototype.init() {
  // build and append modal
}

Modal.prototype.show() {
  // show modal and overlay
}

Modal.prototype.close() {
  // close modal and overlay
}

var modal = new Modal(options);
var btn = document.querySelector('.btn');

btn.addEventListener('click', function() {
  modal.show();
});

D
Daria Motorina, 2019-09-29
@glaphire

Pick up the selector that will select that single button, and remove the class from it)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question