Javascript Error: Cannot read property 'click' of undefined

I am getting the following Console Error:

Uncaught TypeError: Cannot read property 'click' of undefined

it is referencing the following javascript code:

function openChatWindow() {
	document.getElementById("lpHeaderEngagement").childNodes[0].click();
}

Open in new window

tekgrlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zc2Commented:
does the element returned by document.getElementById("lpHeaderEngagement") have any child elements?
0
tekgrlAuthor Commented:
No. No child elements.
0
zc2Commented:
That's why the error occurs. You should check if there any child elements before attempting to call their function.
var header_engagement_first_child = document.getElementById("lpHeaderEngagement").childNodes[0];
if( header_engagement_first_child &&  header_engagement_first_child.click ) header_engagement_first_child.click();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.