Does anyone happen to know a jQuery show/hide div script..... THAT will hide the div if you click anywhere outside... So for example.. You click a button, it shows the div... if you click anywhere else on the page, it then hides that div...
I could add an event to the body, but i don't know if thats the cleanest way..
jQuery show/hide
Moderator: General Moderators
I'm not sure there's any other way. You could add the event to the body only when the div has been clicked however, which will clean it up a bit.
Not sure how to do this with jQuery specifically - I'd use DOM personally.
Not sure how to do this with jQuery specifically - I'd use DOM personally.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Why use jQuery for something so simple?
XHTML elements with triggering event...
Code: Select all
// setStyleById: given an element id, style property and
// value, apply the style.
// args:
// i - element id
// p - property
// v - value
//
function setstylebyid(i, p, v)
{
var n = document.getElementById(i);
n.style[p] = v;
}
//
// The function is below
//
function divshow() {setstylebyid('your_id_here', 'display', 'block');}
function divhide() {setstylebyid('your_id_here', 'display', 'hide');}
Code: Select all
<span onclick="divshow();" onkeypress="divshow();">show div</span>
<br />
<span onclick="divhide();" onkeypress="divhide();">hide div</span>It gets even easier with jQuery.JAB Creations wrote:Why use jQuery for something so simple?
Code: Select all
$('#element').hide();Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact: