Joe Engle
Joe Engle

Reputation: 197

Nothing for innerHTML of div

I am trying to use javascript to grab the innerHTML of an element. The innerHTML is the results of a query ran. Sometimes the query returns no data so there is nothing inside of the div. I do an alert and it says '[object HTMLDivElement]'. I need to account for this when there is no data for the innerHTML in an if statement. Does anyone know how I would do this? How would I write the IF part?

var HSA_EmployeeCont = document.getElementById('HSA_EmployeeCont').innerHTML;
//alert(HSA_EmployeeCont);

if (HSA_EmployeeCont == 'object HTMLDivElement') {
   ...

Upvotes: 0

Views: 169

Answers (2)

Ed_
Ed_

Reputation: 19098

if (!HSA_EmployeeCont) should do the trick.

Your alert should be showing nothing, perhaps you forgot to add innerHTML before you tested with an alert?

Upvotes: 1

tymeJV
tymeJV

Reputation: 104775

Check the length of the innerHTML:

if (!HSA_EmployeeCont.length)
    console.log("Nothing here!");

Upvotes: 1

Related Questions