I am having trouble resolving an issue using traditional JavaScript and was wondering if there is an easy solution using jQuery. I've searched the web and haven't been able to find anything that does exactly what i want to do.
So.. this is what i want to achieve:
I have 2 div's with content, first one is displayed, second is hidden.
Below and outside of these div's i have a single text link which when first clicked, will swap the content on the first div with the second div. When clicked a second time i want it to swap back to first div and so on.. It should toggle between the 2 div's on each onClick every time i click the text link.
To put a bit more context to it, my div's contain a form with 2 labels and text inputs. In the first div the labels say To: and From: In the second div, the order is simply flipped to say From: and then To:
Below the inputs i have a text link that will allow the user to switch the order around to From: and To:
To:
text input
From:
text input
- Text link -
When the text link is clicked i want the content replaced with this:
From:
text input
To:
text input
Here is an example of what i've tried - Note: This is very close to how i want it except when the link is clicked a second time, nothing happens
<script type="text/javascript">
<code>function hideID(objID){
var element = document.getElementById(objID);
element.style.display="none";
}
function showID(objID){
var element = document.getElementById(objID);
element.style.display="block";
}</code>
</script>
<div id="div1">content 1</div>
<div id="div2" style="display:none;">content 2</div>
<a href="" onClick="hideID('div1');showID('div2'); return false;">Reverse</a>
If anyone has any ideas, i would be very greatful
kind regards
~declan