views:

79

answers:

2

I feel like this should work:

   $(".module .one").hover(function() {
     $("#one").addClass('red');
   });

Basically I am hiding all the .children of "#viewport on load (which #one is), then when a separate element is hovered, (in this case .module .one) I want to change something in #viewport, specifically #one.

Basic idea is a variable content window, where when a thumbnail or whatever I put in the modules swaps the content shown in the viewport. Something I am doing wrong?

Here is my full JS:

<script type="text/javascript">
 $(document).ready(function() {
  $(".module .caption").hide();
  $("#viewport").children().hide();
  $(".module").hover(function() {
     $(this).find(".caption").slideDown().end().siblings('.module').addClass('under');
   },function() {
     $(this).find(".caption").slideUp().end().siblings('.module').removeClass('under');   
   });
   $(".module .one").hover(function() {
     $("#one").addClass('red');
   });
 });
</script>

Here is the markup:

<div id="viewport">
  <div id="one">FIRST ONE CONTENT</div><!-- end #one -->
  <div id="two">SECOND ONE CONTENT</div><!-- end #two -->
  <div id="three">THIRD ONE CONTENT</div><!-- end #three -->
  <div id="four">FOURTH ONE CONTENT</div><!-- end #four -->
</div><!-- end #viewport -->

    <div class="module span-1 one">
  <div class="inside">HOVER</div><!-- end .inside -->
    <h1>TITLE</h1>
    <div class="caption down">
      <p>Caption ipsum lorem dolor ipsum lorem dolor ipsum lorem dolor ipsum lorem dolor</p>
    </div><!-- end .caption -->
</div><!-- end .module -->

    <div class="module span-1 two">
  <div class="inside">HOVER</div><!-- end .inside -->
    <h1>TITLE</h1>
    <div class="caption down">
      <p>Caption ipsum lorem dolor ipsum lorem dolor ipsum lorem dolor ipsum lorem dolor</p>
    </div><!-- end .caption -->
</div><!-- end .module -->

The bigger hover function in the middle is for some fancy rollover effects that the modules will perform themselves, but for these purposes I just want to figure out why I can't add a Class to a separate element when another is hovered. Would love some help/advice!

A: 

$("#viewport #one").addClass('red'); references a control with two names? Should this be;

$(".viewport .one").addClass('red');?

edit

I just tried this and it worked;

$(".viewport.one").addClass('red');

You need to remove the space between the two classes.

griegs
Ah my mistake. I was trying to specify the child of #viewport named #one, but I should have just ben doing this: $(".module .one").hover(function() { $("#one").addClass('red'); });Yet, this do doesn't seem to work?
Fuego DeBassi
try $(".module.one") I found this works in some instances. I think because the element has two classes in it. Let me know if this is not working.
griegs
A: 

Do you mean:

 $(".module.one").hover(function() {

If the classes are both on the same dom element, there should be no space between them. A space between the classes would imply that the first is the parent and the second is its child.

Matrym