“Atribut Data” Kode Jawaban

JS mendapatkan atribut data

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 temukan atribut data

//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

Atribut Data

<!--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 mendapatkan nilai atribut data

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

Jawaban yang mirip dengan “Atribut Data”

Pertanyaan yang mirip dengan “Atribut Data”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya