2
<div class="views-row">
<div>
    <h5 class="product-name">
        <a href="#">Dots</a>
    </h5>  
</div>  
<div class="views-field">       
    <div class="field-content">
        <a href="#">
            <img alt="" src="#" />
        </a>
    </div>  
</div>

Here is the jquery:

    $('.views-field').hover(function() {
    $('h5').css('text-decoration', 'underline');
}, function() {
    $('h5').css('text-decoration', 'none');
});

What the above code produces is the hover effect on all class items instead of just the item I am hovering. I tried to add

$(this).parent('views-row').find('h5').css('text-dec', 'under')

but no beans there.

As you could of guessed I am a jQuery newbie and would really appreciate a point in the right direction...

Thanks in advance

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Adam Pflantzer
  • 770
  • 1
  • 7
  • 13
  • can you please include a simple explanation ... ie when i hover of the DOM element with the id of xxx i want the css applied to DOM element yyy .... i actually have no idea what your expected result is ! – Manse Apr 25 '12 at 14:25
  • I don't think the other answers realize that `
    ...
    ` is repeated and that the action should occur only on each row.
    – iambriansreed Apr 25 '12 at 14:39

4 Answers4

3

Try:

$('.views-field').hover(function() {
    $('h5', $(this).closest('.views-row')).css('text-decoration', 'underline');
}, function() {
    $('h5', $(this).closest('.views-row')).css('text-decoration', 'none');
});

You could also use: $(this).parents('.views-row') to attach to that particular row but closest only returns one element.

Fiddled: http://jsfiddle.net/iambriansreed/Ct39b/

iambriansreed
  • 21,935
  • 6
  • 63
  • 79
1

Try $(this).prev().find('h5').css('text-decoration', 'underline');

The above should work if the div containing h5 is always above .views-field.

$('.views-field').hover(function() {
    $(this).prev().find('h5').css('text-decoration', 'underline');
}, function() {
    $(this).prev().find('h5').css('text-decoration', 'none');
});
Selvakumar Arumugam
  • 79,297
  • 15
  • 120
  • 134
  • Would also work better if you didnt abbreviate the css key and value you're trying to edit; Its `text-decoration` and `underline`. – Jamiec Apr 25 '12 at 14:31
  • It wasn;t me but some eejit is just downvoting every answer, mine included. – Jamiec Apr 25 '12 at 14:37
  • yea, sorry about that... i know the correct property and value there.. just trying to save a few keystrokes.. sorry for the confusion – Adam Pflantzer Apr 25 '12 at 14:46
1

I would think the easiest way to do this is scope the h5's to the previous element

$('.views-field').hover(function() {
    $('h5',$(this).prev()).css('text-decoration', 'underline');
}, function() {
    $('h5',$(this).prev()).css('text-decoration', 'none');
});

Here's a jsfiddle which demonstrates: http://jsfiddle.net/v39UQ/

Jamiec
  • 133,658
  • 13
  • 134
  • 193
  • Ha, downvoter is an eejit. This (along with other answers) solves the reqirement, and this one includes a working example. Learn when to use downvotes! – Jamiec Apr 25 '12 at 14:38
-1

See the example here

Here is the code:

<div class="views-row">
<div>
    <h5 class="product-name">
        <a href="#">Dots</a>
    </h5>  
</div>  
<div class="views-field">       
    <div class="field-content">
        <a href="#">
            <img alt="" src="#" />
        </a>
    </div>  
</div>​

$('.views-row h5').hover(function() {
        $(this).css('text-decoration', 'underline');
    }, function() {
        $(this).css('text-decoration', 'none');
    });​

Just your information you can do it using pure css for that code above see below code:

.views-row h5:hover{
    text-decoration: underline;
}
William Calvin
  • 625
  • 6
  • 19