“getAttribute” 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

JS GetAttribute

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

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

Atribut Read Elemen JavaScript

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

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

getAttribute

getAttribute(attributeName)
MAKSTYLE119

Jawaban yang mirip dengan “getAttribute”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya