I have the this code:
<li class="email">
<a href="mailto:abc@gmail.com">abc@gmail.com</a>
</li>
I would like to get the abc@gmail.com using plain JavaScript
I though of doing document.getElementsByTagName("email") which gives me the above, but I don’t have an idea how to continue.
I have managed to find a solution with the help of the below answer by a user
var elem = document.querySelectorAll('.email');
var email = elem[0].children[0].innerHTML;
Demo: http://jsfiddle.net/ThiefMaster/Cx2VY/
However,
document.querySelectorAllis not available in all browsers. Some havedocument.getElementsByClassName)which would also work for you. But other browsers have neither. Consider adding Sizzle if you don’t want jQuery etc. It is the selector engine used by jQuery and other libs and takes away the burden of handling the cross-browser stuff from you.When using
querySelectorAllor Sizzle, you could make your code even easier by removing.firstChildand using the selector.email > ainstead.