2

I have a forum, and on every persons post theres a button that allows a moderator to mute someone after reviewing the post/entering hours to mute for in a window using simplemodal. In the code that shows the window, I have long code like

var output = "<div id='msginfo'>...</div>";

and so on. I would like my code to be able to be 'minified' when I'm done with it and a lot of packers/shrinkers crap out when it comes to the html (usually the < and "> stuff.).

How do other web applications manage no HTML in javascript files? are the divs that will be shown just hidden until they're needed or what?

1
  • I would hide the divs until they are needed Commented Nov 28, 2012 at 20:39

2 Answers 2

4

At work, I use ICanHaz for this. It lets you generate DOM elements on the fly from HTML templates (which you can include in the <head> of your HTML file) without having to inline any HTML whatsoever in your Javascript where it's ugly and harder to read.

For a purpose like yours - displaying a modal with a fixed layout - this is probably cleaner than having the modal included and hidden on the page the moment it loads, although there's probably nothing horribly wrong with the latter solution either in this case.

Incidentally, ICanHaz is also a nice solution when you want to asynchronously add content to the page after it has loaded, which may be relevant in a forum context (for e.g. loading new posts without a new page load).

Sign up to request clarification or add additional context in comments.

Comments

1

I usually put on divs: display:none property for hide it then change that with Javascript when needed, so they will be shown.

On the other hand you can make an Ajax call and get the html you need and display appending it to an element.

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.