I have added a JavaScript onclick attribute to an HTML DIV tag.
I am using multiple onclick attributes in a single DIV tag. Each onclick contains various tags.
What I want is when I click one onclick tag it should display its very own tag in the DIV tag.
And when I click another onclick tag it should display its tag in the same tag but it should clear the previous value.
HTML:
<div id="mobi" style="display:none;" class="answer_list" > <a href="main.php">mobile</a></div>
<div id="elec" style="display:none;" class="answer_list" > <a href="main.php">electric</a></div>
<div id="vehi" style="display:none;" class="answer_list" > <a href="main.php">vehicles</a></div>
<div id="home" style="display:none;" class="answer_list" > <a href="main.php">home</a></div>
<div id="pets" style="display:none;" class="answer_list" > <a href="main.php">pets</a></div>
<div id="book" style="display:none;" class="answer_list" > <a href="main.php">book</a></div>
<div id="main">
<p name="answer" value="Show Div" onclick="mob()" >Mobile</p>
<p name="answer" value="Show Div" onclick="ele()" >Electronics</p>
<p name="answer" value="Show Div" onclick="veh()" >Vehicle</p>
<p name="answer" value="Show Div" onclick="hme()" >Home & Furniture</p>
<p name="answer" value="Show Div" onclick="pet()" >Pets</p>
<p name="answer" value="Show Div" onclick="boo()" >Books CD & Hobbies</p>
</div>
JavaScript:
function mob() {
document.getElementById('mobi').style.display = "block";
}
function ele() {
document.getElementById('elec').style.display = "block";
}
function veh() {
document.getElementById('vehi').style.display = "block";
}
function hme() {
document.getElementById('home').style.display = "block";
}
function pet() {
document.getElementById('pets').style.display = "block";
}
function boo() {
document.getElementById('book').style.display = "block";
}