Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to get the data attached with an element in javascript

HTML>
<article
  id="electric-cars"
  data-columns="3"
  data-index-number="12314"
  data-parent="cars">
...
</article>

JS>
const article = document.querySelector('#electric-cars');
// The following would also work:
// const article = document.getElementById("electric-cars")

article.dataset.columns // "3"
article.dataset.indexNumber // "12314"
article.dataset.parent // "cars"
Comment

PREVIOUS NEXT
Code Example
Javascript :: string to accept two characters after point javascript 
Javascript :: detect mi browser 
Javascript :: date format in ngx-csv package in angular 
Javascript :: date regex 
Javascript :: remove attribute disabled 
Javascript :: how to wait in js 
Javascript :: an image gallery is a set of images with corresponding remove buttons 
Javascript :: javascript replace spaces with one space 
Javascript :: ejs / javascript check if array/object exists and is not empty 
Javascript :: javascript iterate over object 
Javascript :: check if a string is alphanumeric 
Javascript :: react how to scroll to element 
Javascript :: Javascript remove array item by value 
Javascript :: Error: open failed: EACCES (Permission denied) react native 
Javascript :: adonisjs livereload 
Javascript :: adonisjs findorcreate 
Javascript :: how to disable all buttons in javascript 
Javascript :: xmlhttprequest post form 
Javascript :: setrequestheader authorization bearer 
Javascript :: readfilesync 
Javascript :: float js precision 
Javascript :: move an element into another jquery 
Javascript :: codewars js Number of People in the Bus 
Javascript :: create element javascript with class 
Javascript :: remove file from input type file jquery 
Javascript :: bootstrap js link not working 
Javascript :: convert file into base64 in javascript 
Javascript :: javascript create variable containing an object that will contain three properties that store the length of each side of the box 
Javascript :: jquery create a button 
Javascript :: pandas to json 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =