SHARE
TWEET

Untitled

a guest Aug 20th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>get h3 test</title>
  6.     <style>
  7.         h3:before{
  8.             content: attr(data-index)"";
  9.             display: block;
  10.         }
  11.     </style>
  12. </head>
  13. <body>
  14.  
  15.  
  16. <div>
  17.     <h3 data-index="">test1</h3>
  18.     <p>test</p>
  19.     <h3 data-index="">test2</h3>
  20.     <p>test</p>
  21.     <h3 data-index="">test3</h3>
  22.     <p>test</p>
  23. </div>
  24.  
  25. <script>
  26.     const getH3 = ()=>{
  27.         let num;
  28.         let i;
  29.         const allH3 = document.querySelectorAll("h3");
  30.         for(i = 0; i <= allH3.length; i++ ){
  31.             num = allH3[i].dataset;
  32.             num.index = Number([i])+1;
  33.         }
  34.     };
  35.     getH3();
  36.  
  37. </script>
  38. </body>
  39. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top