I need to know if the selected element has an ID.
What am I doing wrong?
var selected = document.activeElement;
if (selected.id = "") {
document.getElementById('test3').innerHTML= "is blank";
}
Thanks
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.
Obviously, you can’t test equality with
=. It requires==(identity with type conversion) or===(identity without any type conversion).In any case, it’s a bit safer to do the comparison this way:
if (selected.id)will be true if eitherselected.id == nullorselected.id == undefinedorselected.id == ""which will cover more cases than justif (selected.id == "").