简体   繁体   中英

Open a div at place clicked

I have a rather simple question but i can't seem to find an answer to it. I want when i click on any place on web page a div is opened. how can i accomplish that CSS style. My question is about the position of the div if i add this div inside a table and i want it to be opened each time i click on different rows. Thanks.

Hmmm try something like this:

<table>
<tr onclick="d=document.getElementById('myDiv');if(d.style.display=='block'){d.style.display='none';}else{d.style.display='block';}">
 <td><td>
</tr>
<tr onclick="d=document.getElementById('myDiv');if(d.style.display=='block'){d.style.display='none';}else{d.style.display='block';}">
 <td><td>
</tr>
</table>

<div id="myDiv" style="display:none">
STuff
</div>

There are better ways to do this.. Im not sure if the tr tag has an onclick handler but its worth a try. You could use a javascript library like jquery or mootools .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM