1

I am pretty new to javascript and jquery. I am trying to rotate the contents of 2 div's located within a wrapper div. One div contains a photo and the other some styled text (h1, h3, p, span). It is a gallery of 4 surf boards and there are 4 photos and 4 descriptions. I have been trying to rotate the contents of the div's when the links are clicked. The div that contains the photos rotates fine. I can get one description in the text div(currentBoard) to rotate but after that the only thing that will change are the photos and the description stays static on the first one that was clicked. Since the div containing the text has a class already applied I am using the id to rotate the contents. The actual contents for this div are in the css using :after and :before and as the id's change for this div I am trying to apply the contents to be that of the new id. I just cannot get the text contents div to rotate in sync with the photos div. The code below is what I have now and I have tried many things already. currentBoard is the id in the text div I would like to change. I am assuming I need to somehow remove the old id first then add in the new one but everything I have tried has failed. Any help is greatly appreciated. Thanks!

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(evt) {
$("a:has(img.boardGallery)").click(function() {
var largePath = $(this).attr("href");
var caption = $(this).attr("id");
var currentBoard = $("#currentBoard");    
currentBoard.attr({ id: caption });
$("#photo_large").attr({ src: largePath });
return false;       
}); 
}); 
</script>
RacerNerd
  • 1,579
  • 1
  • 13
  • 31
kma1289
  • 109
  • 1
  • 8

1 Answers1

0

Switching an ID will not change the content of a div.
If you want to change what is displayed in a div, you should just write a new value into the inner html.

Here is a link to a question showing how that is done: How to replace innerHTML of a div using jQuery?

If you want to have one div disappear and another show up, you should do this with CSS properties and change the 'display' property. You can do this with Show() and Hide() in jQuery. Here is a link to a question showing how to do this: jquery show/hide div

Community
  • 1
  • 1
RacerNerd
  • 1,579
  • 1
  • 13
  • 31
  • This is helpful however how do I get the contents to keep rotating as the user clicks the links? The id does work but only works once. I thought it may be possible using remove/addClass() functions as with an image rotater, but I am confused on how to write the code itself. – kma1289 May 19 '14 at 23:55
  • 1
    Using a switch statement and the .html() I was able to get the contents to change upon clicking the links. Was hoping there was a cleaner way to accomplish this. – kma1289 May 21 '14 at 16:27