не выводит алерт
не выводит алерт хотя класс с частью юрл "a-album" есть на странице
var we = document.getElementsByClassName('fl chat_contact_photo'); for (var i = 0; i < we.length; i++) { if((we[i].href).indexOf("a-album") > -1) alert('1') } |
Цитата:
var we = document.querySelectorAll(".fl.chat_contact_photo"); |
не работает я пробовал
<a class="fl chat_contact_photo" href="/a-album/login-godaple1337"><img src="//pics.site.ru/12/foto/b4/87/b487c3be/ea6nghQ==_.jpg?p=m_" alt=""></a>там с пробелом класс |
Цитата:
Цитата:
Цитата:
|
денис77447327,
<!DOCTYPE html> <html> <head> <title>Untitled</title> <meta charset="utf-8"> </head> <body> <a class="fl chat_contact_photo" href="/a-album/login-godaple1337"><img src="//pics.site.ru/12/foto/b4/87/b487c3be/ea6nghQ==_.jpg?p=m_" alt=""></a> <script> var we = document.querySelectorAll(".fl.chat_contact_photo"); for (var i = 0; i < we.length; i++) { if((we[i].href).indexOf("a-album") > -1) alert('1') } </script> </body> </html> |
VM374:3 Uncaught TypeError: Cannot read property 'indexOf' of undefined
at <anonymous>:3:17 пишет в консоли алерт выводит только если явно указать числовой инденкс вместо [i] помогло вот такое решение var we = document.querySelectorAll("a"); for (var i = 0; i < we.length; i++) { console.log(i,we) if((we[i].href).indexOf("a-album") > -1) alert('1') } |
денис77447327,
<!DOCTYPE html> <html> <head> <title>Untitled</title> <meta charset="utf-8"> </head> <body> <a class="fl chat_contact_photo" href="/a-album/login-godaple1337"><img src="//pics.site.ru/12/foto/b4/87/b487c3be/ea6nghQ==_.jpg?p=m_" alt=""></a> <script> var we = document.querySelectorAll("[href*='a-album']"); if(we.length) alert('1') </script> </body> </html> |
Часовой пояс GMT +3, время: 01:36. |