Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello guys,
I'm facing problem;
Suppose i have multiple div in my file like
HTML
<div1></div1> <div4></div4>
<div2></div1> <div5></div5>
<div3></div1> <div6></div6>


Now what i want to do is to show content of div 4 when i roll over my mouse on div1,similarly when i roll my mouse on div2 it should show info about div 5 but at the same time hiding info about div4 and so on.I want to do it dynamically by limiting use of id to call function on each div.So far iam able to display it for one div but when i go for another div i have to assign new id to it so that i can the function on it.
My question is there some other way because my div will be dynamically generated so i cant add id at run time.
Posted
Updated 26-Feb-13 2:29am
v2

Yes you can add ID at runtime.I dont know in which language you are working, but as per my knowledge you can add dynamic ID using any language(like jsp,php etc)
 
Share this answer
 
Here is the Sample code that u can use.


XML
<style type="text/css">
  #div4, #div5, #div6 {
    visibility: hidden;
  }
</style>
<script>
  function show(id) {
    document.getElementById(id).style.visibility = "visible";
  }
  function hide(id) {
    document.getElementById(id).style.visibility = "hidden";
  }
</script>

<div onMouseOver="show('div4')" onMouseOut="hide('div1')">
  <div id="div4">Div 4 Content</div>
</div>
<div onMouseOver="show('div5')" onMouseOut="hide('div5')">
  <div id="div5">Div 5 Content</div>
</div>
<div onMouseOver="show('div6')" onMouseOut="hide('div3')">
  <div id="div6">Div6 Content</div>
</div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900