Gundon
Gundon

Reputation: 2121

ways of conditionally writing html

I want to detect if the browser supports different functions:

   var useWrappedLayout = (document.getElementById != undefined);

I have to support quite old devices, thats why I check for getElementById.

Depending on if useWrappedLayout is true or not, I want the page to have some HTML-Elements or not.

For keeping things simple and to have an example, lets say I only want to have

 <p>Test</p>

between

 <b>A</b><i>C</i>

if useWrappedLayout is true.

What methods do I have? Only innerHTML?

Upvotes: 0

Views: 154

Answers (1)

Scott
Scott

Reputation: 21501

Building the HTML dynamically using javascript

<script type="text/javascript">
    var useWrappedLayout = (document.getElementById != undefined);
    document.write("<b>A</b>" + ((useWrappedLayout) ? "<p>Test</p>" : "") + "<i>C</i>");
</script>

Upvotes: 1

Related Questions