/    Sign up×
Community /Pin to ProfileBookmark

Hiding/Showing div in a single onclick event

Hi,

I just installed a javascript library (Walter Zorn drag and drop: [url]http://www.walterzorn.com/dragdrop/dragdrop_e.htm[/url]) and one of the properties included is the ability to hide or show divs and images that have been made draggable, using the the following methods:

if (window.dd && dd.elements)dd.elements.divID.show()

and

if(window.dd && dd.elements) dd.elements.divID.hide()

I’m wondering if I wanted to make a single button that toggled between hiding and showing a DIV….how would I combine the two methods in a single onclick event, to toggle visibility? They both work perfectly as separate events on different buttons but I cannot figure out how to combine them. Any help would really be appreciated. I’m hope there’s some way to do this w/ the “else” statement but I don’t know the proper syntax.

Thanks!!!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@javawebdogJan 26.2010 — [CODE]function toggleNotes(){
state=document.getElementById('notestoggle').value;
if (state == "Hide Special Notes"){
document.getElementById('specialnotes').style.display="none";
document.getElementById('notestoggle').value = "Show Special Notes";
}

if(state == "Show Special Notes"){
document.getElementById('specialnotes').style.display="";
document.getElementById('notestoggle').value = "Hide Special Notes";
}
}
[/CODE]


In addition to managing the swap in one function it also relabels the button.
×

Success!

Help @clerner spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...