show/hide div elements in exact same position

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 8146 Views - Last Post: 04 September 2011 - 10:21 AM

#16 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: show/hide div elements in exact same position

Posted 04 September 2011 - 12:39 AM

Did you insert the closing });?
Was This Post Helpful? 0
  • +
  • -

#17 polska03  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 302
  • Joined: 28-November 09

Re: show/hide div elements in exact same position

Posted 04 September 2011 - 12:45 AM

yes they are there, I just forgot to add them in my last post
Was This Post Helpful? 0
  • +
  • -

#18 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: show/hide div elements in exact same position

Posted 04 September 2011 - 12:46 AM

Ok, I will look into it. Give me some time, I must bathe and have lunch!
Was This Post Helpful? 0
  • +
  • -

#19 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: show/hide div elements in exact same position

Posted 04 September 2011 - 03:46 AM

No need to use $(element).wrap(), the following code will suffice:

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var sec = $("#second").html();
var fir = $("#first").html();
$("#second").remove();
$("button").click(function() {
if (this.id == "a") {
$("#content").empty();
$(fir).appendTo($("#content")); }
else {
$("#content").empty();
$(sec).appendTo($("#content")); }
});
});
</script>
</head>
<body>
<div id = 'container'>
<button id = "a">First!</button>
<button id = "b">Second!</button>
<div id = 'content'>
<div id = "first">
<p>I am first!</p>
</div>
<div id = "second">
<p>I am second!</p>
</div>
</div>
</div>
</body>
</html>


This post has been edited by cupidvogel: 04 September 2011 - 03:55 AM

Was This Post Helpful? 1
  • +
  • -

#20 polska03  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 302
  • Joined: 28-November 09

Re: show/hide div elements in exact same position

Posted 04 September 2011 - 10:17 AM

Works Thank you so much!! thanks for all your time you put into this.

This post has been edited by polska03: 04 September 2011 - 10:19 AM

Was This Post Helpful? 0
  • +
  • -

#21 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: show/hide div elements in exact same position

Posted 04 September 2011 - 10:21 AM

There is nothing wrong with the code, trust me! Go to My link, and paste this entire code there and run it. Go on, give it a try..

Oh it works? Fine then. Amen. :bananaman:
Was This Post Helpful? 0
  • +
  • -

#22 polska03  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 302
  • Joined: 28-November 09

Re: show/hide div elements in exact same position

Posted 04 September 2011 - 10:21 AM

I simpyl copied and pasted and tried it out and then figured the source for jquery wasent a file I had, so I just used
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
your code is great, Thanks again so much!
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2