“JS GetAttribute” Kode Jawaban

cara mendapatkan elemen dengan nilai atribut di javascript

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

JS GetAttribute

const link = document.querySelector('a');

console.log(link.getAttribute('href'));
Gendzi

Atribut Read Elemen JavaScript

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

getAttribute JavaScript

<!-- example div in an html DOC -->
<div id="div1">Hi Champ!</div>

// in a console
const div1 = document.getElementById('div1');
//=> <div id="div1">Hi Champ!</div>

const exampleAttr= div1.getAttribute('id');
//=> "div1"

const align = div1.getAttribute('align')
//=> null

Anthony Smith

getAttribute

<!-- example div in an HTML DOC -->
<div id="div1">Hi Champ!</div>

// in a console
const div1 = document.getElementById('div1');
//=> <div id="div1">Hi Champ!</div>

const exampleAttr= div1.getAttribute('id');
//=> "div1"

const align = div1.getAttribute('align')
//=> null
Anthony Darter

Jawaban yang mirip dengan “JS GetAttribute”

Pertanyaan yang mirip dengan “JS GetAttribute”

Lebih banyak jawaban terkait untuk “JS GetAttribute” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya