var link = document.querySelector('a[href$=php]'); var str = link.previousSibling.textContent; alert(str);