1

I am looking for a nice way to change the visibility of an HTML div.

The probably most common way to do this, is by using JavaScript, since it can manipulate my DOM. In my current project, I prefer not to use any JavaScript, so here is my question:

Is there another way to solve this, by using technologies like Ruby or Sass?

I am using in my project Ruby + the Sinatra Framework, as well as Haml and Sass.

7
  • I know the JS way would be: ` ... { document.getElementById("visible").style.visibility = "hidden"; } ... ` Commented Nov 22, 2012 at 19:34
  • 1
    Do you want to do it dynamically, after the user has loaded the page, or while the page is being served? If it's after the page has been served and the browser is displaying it, then this isn't a Ruby question, it's purely JavaScript. Commented Nov 22, 2012 at 19:37
  • 1
    Javascript will not manipulate your stylesheet but the dom tree loaded in the browser. Without using javascript you can use sessions and reload page, letting the display of the div logic at server side. Commented Nov 22, 2012 at 19:39
  • 1
    After the page has loaded and without using javascript will not be possible unless you refresh your page every x seconds ... Commented Nov 22, 2012 at 19:44
  • 1
    display: none is usually the preferred way of hiding an element as it completely removes the element instead of leaving a gaping hole like visibility: hidden does. There is an element in HTML5 (details) that has a show/hide behavior, but it should only be used if it is appropriate semantic-wise (support is poor at the moment: Chrome/Safari only). Commented Nov 22, 2012 at 19:48

1 Answer 1

1

I am not sure with HAML syntax. Whether the below fit for you need?

- if hide_div?
  %div {:style=> "display:none;"}
- else
  %div {:style=> "display:block;"}
- end
Sign up to request clarification or add additional context in comments.

Comments

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.