# Accessing to attributes via methods in JavaScript

Custom attributes can also be accessed using methods like `getAttribute`, in which case the full name of the attribute should be written:

`<div id="elem" data-num="1000" data-my-num="2000"></div>` `let elem = document.querySelector('#elem'); console.log(elem.getAttribute('data-num')); // shows 1000 console.log(elem.getAttribute('data-my-num')); // shows 2000`

Given paragraphs. Go through them in a loop and for each paragraph write down the ordinal number of this paragraph into the `data-num` attribute. Use the `setAttribute` method.

← →
↑
en ru