Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <p>
- Piłka nożna
- </p>
- <p>
- Siatkówka
- </p>
- <p>
- Narciarstwo
- </p>
- <script>
- const pArray = document.querySelectorAll('p');
- pArray.forEach((p, index) => {
- if(index !== 0) {
- pArray[index].addEventListener('click', () => {
- console.log(pArray[index].textContent)
- const tempP = pArray[0].textContent;
- pArray[0].textContent = pArray[index].textContent
- pArray[index].textContent = tempP
- })
- }
- })
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement