on-internet
← Community

JavaScript and HTML to show or hide an element

Stack Overflow ·

I think this is very easy, but I just can't seem to twig it at the moment. I want to use a JavaScript function to set the visibility of an HTML tag. I realise the below is wrong as hidden doesn't take a boolean. I'm just struggling to click what the easiest way to do it is? So I have some script like this: <script> function evaluateBoolean() { if (location.hostname.indexOf("someval" > 0) { return true; } else { return false; } } </script> And I wanted to use it something like this: <div hidden="evaluateBoolean()"> this will be shown or displayed depending on the JavaScript boolean </div>

Comments

Sign in or sign up to comment and upvote.

No comments yet.