Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

dataset js

for javascript : 
webappData.getAttribute('data-id');
document.querySelector('#elementId').dataset.id = 'value';

for jquery : 
$(element).attr('data-key', 'value');
Comment

javascript dataset

//html file
<div id="user" data-user-id="2" data-user-date-of-birth="03/03/1993">
 <p> Hello ! </p>
</div>

//js file
const user = document.getElementById('user')

console.log(user.dataset.userId) // => 2

console.log(user.dataset.userDateOfBirth) // => '03/03/1993'
Comment

dataset js

const el = document.querySelector('#user');

// el.id === 'user'
// el.dataset.id === '1234567890'
// el.dataset.user === 'johndoe'
// el.dataset.dateOfBirth === ''

// set a data attribute
el.dataset.dateOfBirth = '1960-10-03';
// Result: el.dataset.dateOfBirth === '1960-10-03'

delete el.dataset.dateOfBirth;
// Result: el.dataset.dateOfBirth === undefined

if ('someDataAttr' in el.dataset === false) {
  el.dataset.someDataAttr = 'mydata';
  // Result: 'someDataAttr' in el.dataset === true
}
Comment

dataset javascript

<body>
<div id = "id_name" data-tagName = "value" data-tagName1 = "value">
Display Data
</div>
<script>
const variable_name = document.getElementById('id_name');
console.log(variable_name.dataset);
</script>
</body>
Comment

js dataset

<div id="user" data-id="1234567890" data-user="johndoe" data-date-of-birth>John Doe</div>

const el = document.querySelector('#user');

// el.id === 'user'
// el.dataset.id === '1234567890'
// el.dataset.user === 'johndoe'
// el.dataset.dateOfBirth === ''
Comment

PREVIOUS NEXT
Code Example
Javascript :: (error) = { console.log(error); } 
Javascript :: js setinterval vs settimeout 
Javascript :: js for of 
Javascript :: modern javascript for loop syntax 
Javascript :: react maps 
Javascript :: javascript loop an array check if a number is even 
Javascript :: what difference between react func and class components 
Javascript :: pop array 
Javascript :: 8.1.2. Array Length¶ 
Javascript :: google geocode nodejs 
Javascript :: javascript check if variable is empty 
Javascript :: array javascript 
Javascript :: fs.appendFileSync in nodejs 
Javascript :: combine the values of 2 arrays in key = value jquery 
Javascript :: get index of item with attribute javascript 
Javascript :: timing code in javascript 
Javascript :: js or 
Javascript :: moment.set 
Javascript :: how to import pdfmake/build/pdfmake.min in react 
Javascript :: check object has key javascript 
Javascript :: User Input from Javascript Console 
Javascript :: recharts change scale 
Javascript :: JavaScript BLOCK ENTER 
Javascript :: select multiple id in jquery 
Javascript :: Sort an array by both ascending and descending order in js 
Javascript :: angular get class list for element 
Javascript :: get size of array in bytes javascript 
Javascript :: reduce 
Javascript :: regex not js 
Javascript :: angular pass async pipe value to funciton 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =