The estate cursor:pointer
does not simulate a behavior for a given situation? If so, why is it defined via CSS and not only by Javascript?
JS does not simulate the behavior of the element, it simulates the behavior of the mouse cursor. Note that HTML has several elements that by convention use the mouse cursor to give a feedback visual for the user. For example the tag <a>
uses the cursor:pointer
and the tag <input>
uses the cursor:text
. Put a cursor:text
in a <div>
will not change the behavior of <div>
will only confuse the user, as he may understand that it is possible to type a text in the div
...
There are a number of cursor types. Microsoft has already addressed this in this article: https://docs.microsoft.com/pt-br/windows/desktop/uxguide/inter-mouse
Well designed user interface (UI) objects are considered
as affordance, which are visual and behavioural properties
of an object that suggests how it is used. The pointer functions as a
proxy for the hand, allowing users to interact with objects from
screen very similar to physical objects.
This means that the cursor is an extension of the user’s hand, and it takes into consideration the type of pointer to know how it will interact with the element, whether it is clicking, dragging, typing, etc...
Another point is with respect to accessibility. Tags <button>
, <label>
and <input>
for example are interpreted in a way by screen readers, and the "type" of cursor will hardly matter to them. The main thing in this case is to worry about code semantics, the correct use of attributes roles
and of aria
You can read about them here: https://tableless.com.br/wai-aria-estendendo-o-significado-das-interacoes/
Observing: Right click, double click (double click) and click with the key modifiers Shift
or Ctrl
are three mouse interactions that are not intuitive because they have no real-world counterparts.
What does Javascript really do when adding this cursor? Adds a style to the CSS element?
Yes it adds the style on time, but changing cursor is not doing a :hover
. Note that your code changes the cursor by putting a style cursor:pointer
directly in the tag (type one style inline
), but when you take the cursor off the element it continues with the cursor:pointer
set in the tag. What your script does is not exactly a :hover
and a screen reader wouldn’t understand that a :hover
and would not "see" that the course was changed...
The :hover
will always exist, once the DOM and CSSOM are built all elements will already have their style :hover
declared by CSS, already with JS vc will only apply the style when the event happens in the element, something that can even depend on the hardware or the user connection to have a good performance. As you saw in the image the style of the cursor does not exist yet until the user interacts with the element. Already with CSS the style will already be "programmed", is something like the "will change
", where the browser already knows that element will suffer an interaction or animation. https://developer.mozilla.org/en-US/docs/Web/CSS/will-change
In relation to other CSS properties added over an element, it "takes" the same attitude as the cursor?
I believe so, but I can’t say exactly how the browser and the screen readers understand JS, because in most cases they are events that are only triggered when the user does some interaction. Some of the events do not run when the page loads, but only when there is some action on the part of the user. What I can say is that the type of the cursor does not change the type of the element.
For reading:
Just sensational! Everything you needed to know to understand better!
– João Pedro Schmitz
@Joãopedroschmitz glad he gave you a light. Don’t let me read the links I mentioned, even if it’s a dynamic rss reading
– hugocsl