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 :: es6 array sum javascript 
Javascript :: string to object 
Javascript :: @input and @output in angular 
Javascript :: setinterval stop onditional stop 
Javascript :: change data js 
Javascript :: urlencoded limit nodejs 
Javascript :: discord.js remove every role a user has 
Javascript :: promise.all async await 
Javascript :: slice javascript string 
Javascript :: data type javascript 
Javascript :: json objects 
Javascript :: node js async delay 
Javascript :: react router active link 
Javascript :: javascript example of foreach loop 
Javascript :: wordpress disable jquery migrate 
Javascript :: check if browser is internet explorer js 
Javascript :: js different 
Javascript :: set dynamic route in link react js 
Javascript :: header logo react native img 
Javascript :: sum all numbers in a range javascript 
Javascript :: settimeout javascript for loop 
Javascript :: how to change the first Letter to uppercase js 
Javascript :: get bottom position of element javascript 
Javascript :: javascript get multiple elements by id 
Javascript :: jquery next sibling with class 
Javascript :: create node js api 
Javascript :: diagonal Difference in 2D arrays javascript 
Javascript :: window.scrollto(0 0) not working 
Javascript :: node.js query parameters 
Javascript :: js function string parameter 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =