Good day!

Here there is a button that creates carbon atoms with different numbers, so that you can carry out manipulations with each atom separately (for example, drag across the screen using the draggable Jquery UI function). And also there are two checkbox'a .
The first checkbox includes a function that, when you click on the h1 atom, creates a '+' sign. The second checkbox also works, only creates another sign - '-' .
Atoms are created by the constructor, which inherit from the prototypes the methods that generate the charges of the atom.

For example, we created an atom and put a '-' sign on it, having disabled the checkbox of the '-' sign, we can enable the checkbox with the '+' sign. When we click on an atom, the '-' sign will disappear and the '+' sign will appear. Also vice versa - when the '+' sign was first created, the '-' removes the '+' sign and the '-' appears.

The problem is that when several atoms have signs '+' ( '-' ), then when you try to change one atom from '+' to '-' , everything changes to '-' .

Help me figure out how to make one atom change the charge sign, not all at once?

  • A pretty overloaded description, and your example does nothing. - user207618

1 answer 1

If I correctly understood the problem, then to solve it, you need to replace lines 69, 81 (in fidle) with: $(".negative_charge", this).remove(); and $(".positive_charge", this).remove(); respectively.

The second parameter ( this ) in the selector indicates the node in which to search. Thanks to him, $(".positive_charge", this) will select + ( - ) only inside the current element, and not in the whole tree.

  • Thanks, helped! - Art87