Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Open <div> in one question, close it in another

More
7 years 11 months ago #135217 by Svewa
Hi everybody,

I have a rather uncommon question, so to speak:

I would like to open a div container in one question and close it within another, after I place several questions within this container so I can hide it later on using the CSS-Layout. But everytime I save the question with an open div it automatically closes it up (probably to prevent errors). Normally I would be thankful for this function but I would like to turn it off in this case. Can anybody tell me how this might be possible, that would be truly great =)

Thank you guys in advance! :)
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 11 months ago #135226 by holch
Is this happening in pure code view also? Because usually if you write code there it will not be corrected in anyway.

Why do you want to hide those questions via CSS?

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 11 months ago #135250 by tpartner
As holch suggests, you can do this with the WYSIWYG editor disabled but you will need to ensure that the question is never edited with the WYSIWYG in the future.

I'm not sure you will get valid HTML anyway. For example, it seems to me that a <div> opened in one question and closed in another will cause the closing </div> tag for Q1 to be inside another <div> which is invalid.

I would use jQuery to wrap the questions - api.jquery.com/wrapall/

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 11 months ago #135264 by holch
@Tpartner: I haven't followed the latest HTML coding standards too closely, but why would be a DIV in a DIV not valid? We could argue if it is good style or not and that we should try to use the semantically correct tags, but I don't see why a block element could not contain another block element...

I was searching a bit and I couldn't find any reference of a div in a div not being valid HTML. Do you have a link for that?

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 11 months ago - 7 years 11 months ago #135274 by tpartner
Of course, a div in a div is acceptable, what I'm referring to is a div starting in one div and ending in another.

Code:
<div class="question-1">
  <!-- Start of inserted div -->
  <div class="inserted-div">
</div>
<div class="question-2">
  </div>
  <!-- End of inserted div -->
</div>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 11 months ago by tpartner.
The following user(s) said Thank You: Svewa
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 11 months ago #135279 by holch
Ahhh, of course Tony! Makes total sense!

Now looking at your example, the problem is not that it is not valid. The code is perfectly valid. Because the inserted div will be basically closed the the closing div-tag that is supposed to close the question 1 div. Then the question 2 div opens and includes basically question 2 within the question 1 div. The question 2 div is closed by the inserted closing div tag and then the last div closes question 1.

Perfectly valid, but it goes totally against what the divs are supposed to do...

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 11 months ago - 7 years 11 months ago #135280 by holch
Probably my last post was a little confusing.
Code:
<div class="question-1">
  <!-- Start of inserted div -->
  <div class="inserted-div">
</div>
<div class="question-2">
  </div>
  <!-- End of inserted div -->
</div>

The code should be interpreted by the browser like this:
Code:
<div class="question-1">
  <div class="inserted-div">
</div>  // Originally this should close the "question-1" div, but it actually closes the "inserted-div" already
<div class="question-2">
        </div> // This one was supposed to close the "inserted-div", but what it actually does now is closing the "question-2" div already.
  <!-- End of inserted div -->
</div> // This one originally should close "question-2", but now it closes "question-1"

Totally valid code, just doesn't work as it is intended.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Last edit: 7 years 11 months ago by holch.
The following user(s) said Thank You: Svewa
The topic has been locked.
More
7 years 11 months ago #135344 by Svewa
Thank you so much for your answers, you helped me a lot. However, now I might one follow-up question:

- How can I assign a class to a certain question?

The thing is, I am copying the code of one question into another, so I can have a five-star rating within a text shown. The problem is, the question pops up twice on the same page. Once in the spot where it is supposed to pop up when considering LimeSurvey and the other time where I copied the code. Clearly I only want the copied question to show up and the other question to disappear. But if I address the question directly via id-Tag it of course affects both questions. So if I could assign a class to a question that would be the easiest thing, but I don't see how I can get around to that. Maybe this clarifies the aim I am trying to achieve. Thanks again for the great support!!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 11 months ago - 7 years 11 months ago #135347 by tpartner
If both questions are on the same page you can use jQuery to move the five-star question into the text-display question.

Something like this for the 2.06 default template:

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){    
    $('#question2 .questiontext').append($('#question1'));
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 11 months ago by tpartner.
The following user(s) said Thank You: Svewa
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose