“atributos de dados” Respostas de código

JS Get Data Attribui

var element = document.querySelector('.element');
var dataAttribute = element.getAttribute('data-name');
// replace "data-name" with your data attribute name

console.log(dataAttribute);
Eloquent Design

HTML JavaScript Encontre o atributo de dados

//javascript get html data attribute
<button data-id="1" >Click</button>
<button data-id="2" >Click</button>
<button data-id="3" >Click</button>
const btns=document.querySelectorAll('button[data-id]');
[...btns].forEach(btn => console.log(btn.getAttribute('data-id')))
CuteKittyCat

atributos de dados

<!--data-* attributes allow us to store extra information on standard 
, semantic HTML elements.
-->
<article
  id="electric-cars"
  data-columns="3"
  data-index-number="12314"
  data-parent="cars">
...
</article>
<!-- Accessing via JS -->
<script>
  const article = document.querySelector('#electric-cars');
  article.dataset.columns // "3"
</script>
<!--css-->
<style>
  article::before {
  content: attr(data-parent);
 }
  article[data-columns='3'] {
  width: 400px;
}

</style>
Bug Killer

JavaScript Get Data Atributo Valor

const article = document.querySelector('#electric-cars');
 
article.dataset.columns // "3"
article.dataset.indexNumber // "12314"
article.dataset.parent // "cars"
Curious Crossbill

Respostas semelhantes a “atributos de dados”

Perguntas semelhantes a “atributos de dados”

Procure respostas de código populares por idioma

Procurar outros idiomas de código