0

I have been trying to change this div tag's style when an image is clicked, and its not working. First I want to check and see if the style is "display:none;" or "display:block". But when I try to alert the value it returns "undefined" for both when the display is set to none and when it is set to block.

<div id="navbar-mobile-id" style="display:block;" class="navbar-mobile">

This is in my function: (function works when clicked but alerts "undefined")

alert(console.log(document.getElementById("navbar-mobile-id").style.display));

This should alert either "block" or "none"

1
  • 1
    alert(console.log("hi")) is also going to alert undefined. Why is an console inside the alert? Commented Aug 21, 2019 at 14:16

1 Answer 1

7

The return value of console.log() is undefined

If you want to alert the value of the display property, then you have to alert that.

alert(document.getElementById("navbar-mobile-id").style.display);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.