Copy link to clipboard
Copied
Hi all,
In php - we can do and if statement something like:
<?php if ($test1 !=''){
?>
add HTML HERE
<?php
// end if here
} ?>
and the html will only show if the condition is met.
Q: So, What's the best way to add large html chunk like a form using javascript IF statement or a better way???
like this - or...???
<script>
if ( test1 !="" ){
//this....
document.getElementById('showthis').innerHTML = "large html chunk";
}
// or this....
$.get("codeblock-1.html", function(fileData){
$('put-stuff-here').html(fileData);
});
// or something better?
</script>
Copy link to clipboard
Copied
Hi all,
Someone mentioned using CSS hide which worked well but ultimately I found this:
And it really did the trick.... (& TREAT)!!!
Copy link to clipboard
Copied
Using that is fine for hiding a form, but be careful about using it for elements that contain images. The jQuery hide() method sets the CSS display property to none, but all the content will still be downloaded.
Copy link to clipboard
Copied
I agree with David, I think you're better off making the conditional check first and actually loading the HTML after that.
I don't presume you're getting extremely deep into JavaScript content generation if you're dumping a lot of string data into the DOM but for the record, the DOM Fragment is a lean machine for generating any verbose content via JavaScript. Using it would even allow you to half the loading of images before they're needed. In short terms, every time you do "anything" to the DOM (like add content, any kind), the whole thing needs to reflow to take your changes into consideration. DOM Fragments can be created entirely on the side and do not cause this to happen, UNTIL you're done generating your DOM and you append it to the document.
It's may be a bit more of an advanced topic than you need but here's more info about performance and examples:
Copy link to clipboard
Copied
THANKS SO MUCH DAVID & sinious !!!
YOU HAVE BEEN SO HELPFUL & I want to thank you for all your great advice!!!!
HAPPY HOLIDAYS!!!!