0

I have several instances of

(".wrappingdivclass > .hovercontents > .hovercontent2")

on a page.. all need to behave independently but call the same jquery. As you can see its two blocks of identical HTML...

how would I go up/down the dom tree to keep the hover/showhide on ONLY the stuff within the wrappingclass div, and not affect everything the next wrappingclass div also.

<div class="wrappingclass" id="notthesecondone">
 <div class="hoverheaders">
     <p class="hoverheading">on hover display stuff</p>
     <p class="hoverheading1">on hover display stuff1</p>
     <!-- iterate, as needed !-->
    </div>
     <div class="hovercontents">
      <p class="hovercontent">stuff</p>
      <p class="hovercontent1">stuff1</p>
              <!-- iterate, as needed !-->
  </div>
    <div class="wrappingclass" id="notthefirstone">
 <div class="hoverheaders">
     <p class="hoverheading">on hover display stuff/hide stuff1</p>
     <p class="hoverheading1">on hover display stuff1/hidestuff</p>
     <!-- iterate, as needed !-->
    </div>
     <div class="hovercontents">
      <p class="hovercontent">stuff</p>
      <p class="hovercontent1">stuff1</p>
              <!-- iterate, as needed !-->
  </div>

Here is the jquery:

//does not work
jQuery(document).ready(function() {
  jQuery(".hovercontent").show();
  //toggle the componenet with class msg_body
  jQuery(".hoverheading").hover(function()
  {
     jQuery(this).parent().children(".hovercontent").show()
    jQuery(this).parent().children(".hovercontent").siblings().hide();
  });
});

1 Answers1

0

Try replacing

jQuery(this).parent().children(".hovercontent").show()
jQuery(this).parent().children(".hovercontent").siblings().hide();

with

jQuery('.hovercontent').hide();
jQuery(this).closest('.hovercontent').show

Edit

Replace hover with mouseover

Final Edit,

Its acutally like this.. (inside DOM ready)

$("p[class^=hovercontent]").hide();
//toggle the componenet with class msg_body
$("p[class^=hoverheading]").mouseover(function() {
    $("p[class^=hovercontent]").hide();
    $(this).closest('.hoverheaders').next().find('p').eq($(this).index()).show();
});​

Demo - http://jsfiddle.net/68UVj/

Atif
  • 10,623
  • 20
  • 63
  • 96