I am trying to get the text of all hyperlinks in my web page and check whether the text is "selected". If it is "selected", an alert showing the id will be prompted.
However, when I tried to use inputs[i].value to get the text of the , the result I gets was "undefined".
How can I go about doing it?
The following codes are for my hyperlinks:
<a href="www.google.com" id="1">selected</a>
<a href="www.facebook.com" id="2">select</a>
<a href="www.gmail.com" id="3">selected</a>
<button onclick="check()">Check!</button>
The following codes are for my javascript:
function check() {
var inputs = document.getElementsByTagName('a');
for(var i = 0; i < inputs.length; i += 1) {
if (inputs[i].value == "selected")
{
alert(inputs[i].id);
}
}
}