Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Using DOM Nodes As Keys

<span id="el1">first element</span>
<span id="el2">second element</span>

<script>
  const someObj = {
    [document.getElementById('el1')]: 'some value'
  };

  console.log(someObj[document.getElementById('el1')]);
  // 'some value'
</script>
Comment

Using DOM Nodes As Keys

<span id="thing" class="thing">a thing.</span>

<script>
const myWeakMap = new WeakMap();

// Set a value to a specific node reference.
myWeakMap.set(document.getElementById('thing'), 'some value');

// Access that value by passing the same reference.
console.log(myWeakMap.get(document.querySelector('.thing')); // 'some value'
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to filter data in javascript object 
Javascript :: find minimum length word in a phrase 
Javascript :: javascript chessboard embedding 
Javascript :: get members of a group graph pnp js 
Javascript :: Remove the warning for setState on unmounted components in React 
Javascript :: how to place text input cursor to start in react native 
Javascript :: Install Date-Time in express.js 
Javascript :: get form control value in angular 8 
Javascript :: es6 parameter destructuring nested object 
Javascript :: javascript to send email on button click 
Javascript :: vanilla js for each element add attribute 
Javascript :: animating in activityindicator 
Javascript :: ubicar escrol en el final jquey 
Javascript :: javascript array filter exercises 
Javascript :: zxaas 
Javascript :: jquery set radio button checked 
Javascript :: multiple parameters in url Servlet 
Javascript :: js array piush 
Javascript :: override submit button javascript 
Javascript :: mixed line chart for angular or react 
Javascript :: unban command discord.js v12 
Javascript :: object.keys map 
Javascript :: threee.js camera to point 
Javascript :: onclick clear input field javascript 
Javascript :: how to use bootstrap in reactjs 
Javascript :: cypress replace response part 
Javascript :: get decimal on number javscri 
Javascript :: nodejs sqlite3 db. insert 
Javascript :: JavaScript code to convert amount in words 
Javascript :: palindromes array number 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =