Why is the draggable attribute with the false value not working?

Asked

Viewed 69 times

1

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <p draggable="true">Esse parágrafo é arrastável.</p>
    <p draggable="false">Esse parágrafo não é arrastável.</p>
</body>
</html>

The attribute draggable is used to define whether a particular element is draggable or not. By default images and links are draggable, but in the case of the above example paragraphs are draggable even if the attribute draggable is omitted and in the case of the second paragraph even giving a draggable="false" the paragraph continues to be dragged, why does this happen? it was not for the paragraph not to be dragged?

  • But he is draggble

  • Where are you running this?

  • @Diego Filipe Pedro Santos, No Chrome!

  • The latter is disabled, but does not deactivate!

  • It’s exactly this code that you’re trying to run why even in jsfiddle runs

  • @hugocsl, the attribute draggable is an enumerated attribute if the value is true the element is trawlable and if false the element is not draggable, but even giving false the element remains draggable.

  • @Diego Filipe Pedro Santos, the paragraph is not being dragged?

  • No, look there https://jsfiddle.net/zb910pqu/7/

  • In the snippet above the paragraph is not being draggable.

Show 5 more comments

1 answer

1


As I told you it’s already working, I believe you’ve understood the draggable of HTML mistakenly, thinking he would function as the draggable of jQuery, only that.

Look at this image as a simple example, and see how draggable="true/false" it is possible to determine which elements may or may not be dragged. And see tb pq it is interesting that some of them actually are draggables, especially for those who have a device without teclado and has only the mouse as a resource.

inserir a descrição da imagem aqui

<p draggable="true">Esse parágrafo é arrastável.</p>
<p draggable="false">Esse parágrafo não é arrastável.</p>

<img draggable="true" src="https://www.placecage.com/100/100">
<img draggable="false" src="https://www.placecage.com/100/100">

<a draggable="true" href="https://www.google.com">google</a>
<a draggable="false" href="https://www.google.com">google</a>

  • but when the text is selected it remains draggable what to do ?

  • @ledeveloper dunno bro... If you gave the draggable attribute to an element that natively should not have, then you decide. What I see, eh that does not make sense you have a text that is draggable, already a link eh interesting. This is the flexibility of html, you can give a feature that is not native to an element, but whether it is correct or not, or whether it makes sense or not it is on its own

  • 1

    vlw man, for the attention!

  • @ledeveloper might not be exactly what you expected from the attribute, but being native to html would not be anything too "sophisticated"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.