<a href="url">A link</a>
$.each($('a'), function(index,value){
alert (value)
});
It will alert : url.
Why this happens?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s because the
toString()of the anchor gives the URL.Live DEMO
alertcallstoString()implicity on objects. so when you alert an array like:Alerting it will give you:
Because the toString() of
arrayis the elements separated by a comma.If you encounter this problem while debugging, you should use
console.log()instead ofalert()