“JavaScript mendapatkan atribut” Kode Jawaban

JavaScript mendapatkan atribut

//HTML
//<div id="elem" data-id="4hJ3s"></div>

var elem = document.getElementById("elem");
elem.getAttribute("data-id"); // "4hJ3s"
TC5550

cara mendapatkan elemen dengan nilai atribut di javascript

document.querySelectorAll('[data-foo="value"]');
Gogo Dev

Dom Element Get Atribut

document.getElementById('id1').getAttribute('attribute');
Jesus

JavaScript mendapatkan atribut

<div id="id_of_the_element" data-attribute_name="foo"></div>

var elem = document.getElementById("id_of_the_element");
var attribute_value = elem.getAttribute("data-attribute_name");

//OR with jquery...
var attribute_value = $('#id_of_the_element').attr('data-attribute_name');
//OR...
var attribute_value = $('#id_of_the_element').data('attribute_name');
Matteoweb

Dapatkan nilai atribut HTML di JS

<div id="id_of_the_element" data-attribute_name="foo"></div>

var elem = document.getElementById("id_of_the_element");
var attribute_value = elem.getAttribute("data-attribute_name");

//OR with jquery...
var attribute_value = $('#id_of_the_element').attr('data-attribute_name');
//OR...
var attribute_value = $('#id_of_the_element').data('attribute_name');

2nd example

//HTML
//<div id="elem" data-id="4hJ3s"></div>

var elem = document.getElementById("elem");
elem.getAttribute("data-id"); // "4hJ3s"
Clear Copperhead

Dapatkan atribut JS

element.getAttribute('id')
Anthony Smith

Jawaban yang mirip dengan “JavaScript mendapatkan atribut”

Pertanyaan yang mirip dengan “JavaScript mendapatkan atribut”

Lebih banyak jawaban terkait untuk “JavaScript mendapatkan atribut” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya