I'm having some issues with selecting external div to change the css element.
I had:
<script>
$(".shares").hover(function(){
$('.homenetworks').removeClass('hidden');
$('.totalshares').addClass('hidden');
$('.catlink').addClass('hidden');
$('.shareimage').addClass('hidden');
},function(){
$('.homenetworks').addClass('hidden');
$('.totalshares').removeClass('hidden');
$('.catlink').removeClass('hidden');
$('.shareimage').removeClass('hidden');
});
</script>
Which worked to the desired effect, however it applied it to every instance of this on the page. I then found out about $(this).find to only effect the selected one.
<script>
$(".shares").hover(function(){
$(this).find('.homenetworks').removeClass('hidden');
$(this).find('.totalshares').addClass('hidden');
$(this).find('.catlink').addClass('hidden');
$(this).find('.shareimage').addClass('hidden');
},function(){
$(this).find('.homenetworks').addClass('hidden');
$(this).find('.totalshares').removeClass('hidden');
$(this).find('.catlink').removeClass('hidden');
$(this).find('.shareimage').removeClass('hidden');
});
</script>
However this removes the class from .homenetworks and adds the class hidden to .totalshares but it no longer effects .totalshares and .catlink.
The structure of the divs is like so:
<div class="newsbutton">
<div class="catlink">
Link
</div>
<div class="shareimage">
Img
</div>
<div class="shares">
<div class="totalshares">
Shares
</div>
<div class="homenetworks hidden">
Content
</div>
</div>
</div>
I would like when a user hovers over .totalshares it hides totalshares,shareimage,newsbutton and then shows homenetworks. (By using display:none under the css class .hidden).
Anyone got any ideas what is possibly going wrong, can (this).find not search up levels on div structure?
Thanks
(this).findonly searches in childs ofthiselement. To avoid that use siblings() like Arun P Johny mentioned, or use the.parent()function before you use.find()(this only works in your case, not in all, depending on the strukture and the parent elements.)