Alex Tech Adventures The webs best tutorials!

HTML div as reusable block

(0 votes, average 0 out of 5)

In the previous entry I showed how to use <div> as a reusable block to make an unobtrusive popup wizard.  Problem with that entry is that it has too much concepts and one may miss out the advantage of this one particular technique so i am dedicating an entry just for it.


 

This technique involves applying HTML content of a <div> in one part of a page to another, usually a placeholder, so the effect is like calling a function that we are familiar with from other programming languages.

First, you need a placeholder where the reusable HTML will be applied to.  For this example it will be

1
<div id="mainContent"></div>

 


Now create hidden <div>s with the content you want to reuse:

1
2
3
4
5
6
7
<div id="step1" style="display: none>
Step one
</div>
 
<div id="step2" style="display: none">
Step two
</div>

 


To get content of any of the reusable <div>s and use it as a part of the main content use this JavaScript:

1
document.getElementById("mainContent").innerHTML = document.getElementById("step1").innerHTML

 


You can use some logic to dynamically figure out which of the reusable <div>s to be applied.

 

 

 
You need to login or register to post comments.
Discuss...
You are here: Home Development (X) HTML / CSS / JavaScript HTML div as reusable block

Statistics

Members : 1388
Content : 42
Web Links : 1
Content View Hits : 190542

Poll

Interested in TinyBrowser and TinyMce plugin for ZF?
 

Who's Online

We have 25 guests online