View Full Version : Closing a Div With Javascript
jcdevelopment
12-05-2007, 07:46 PM
I have been able to make an application with javascript where you are able to drag and drop divs, now im running into more of a user friendly area. What im wanting to know is there a way to close a div they dont want, or is that more serverside PHP?
VIPStephan
12-05-2007, 08:55 PM
No, that’s JavaScript alright. You would probably generate a “close” button with JS (within the div that’s supposed to be closed) that either hides the div (display: none) or even removes it completely (removeChild (http://javascript.about.com/library/bldom09.htm)).
Actinia
12-05-2007, 08:56 PM
You need to give the div a name Which it presumably has if it is being dragged). Then all you need do is to set the display style to 'none'.
I use a function
function hideItem(divID) {
refID = document.getElementById(divID);
refID.style.display = "none";
}
Those two lines can be condensed into one:
document.getElementById(divID).style.display = "none";
Obviously you need a link to this. I place mine as a [Close] link at the bottom of the div. This has the form:
<h4><a href=# onclick="hideItem(divname);">Close</a></h4>
John Rostron
jcdevelopment
12-05-2007, 09:29 PM
Thanks guys thats what i was looking for. I would thankyou but i guess you no longer can, i wonder why!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.