Skip to content

Bug and a solution to "Mouse events basics" section and "Selectable list" task #123

@Annis-Monadjem

Description

@Annis-Monadjem

Hello Ilaya and thank you very much for you fantastic work on
javascript.info and your positive impact on my learning javascript
and web development. Truly, your site is the very best from what I have seen
till now. My hope is that you will continue with this wonderful project into
the future.
Below I'm suggesting a correction to the task. In Mouse events basics section
and Selectable list task your solution has a bug. The bug: using Ctrl first
select few lines; next release Ctrl and select/unselect one line. Now you
should see what is happening: the lines are not unselected the same way as you
are clicking.
May I suggest this solution, which to my best knowledge is working very well (the head and body are same/unchanged):

  <script>
    ul.onmousedown = function(event)
    {
      return false;
    }
    ul.onclick = function(event)
    {
      if (event.ctrlKey)
      {
        event.target.classList.toggle('selected');
      }
      else
      {
        for (let li of ul.querySelectorAll('li'))
        {
          li.classList.remove('selected');
        }
        event.target.classList.add('selected');
      }
    }
  </script>

PS: I've posted this comment on Disqus site gives me terrible problems e.g. my comments don't show up on javascript.info. Also I cannot follow over people comments on Disqus. I've checked my settings with Disqus, but it's simply not working well. Hence, I'm double posting it this time. Other than that: thank you Ilaya for
javascript.info

PSS: Just to let you know that I've placed earlier 9 comments in Disqus (on javascript.info) but not even one has appeared on Disqus.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions