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

2
  • 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 ! Commented Apr 25, 2012 at 14:25
  • I don't think the other answers realize that <div class="views-row">...</div> is repeated and that the action should occur only on each row. Commented Apr 25, 2012 at 14:39

4 Answers 4

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/

Sign up to request clarification or add additional context in comments.

3 Comments

I don't understand either.. I clicked the check mark... any way to reverse that?
yea, working on that... was that me that downvoted though? I sure hope not because your solution was perfect.
@AdamPflantzer No you need a rep of > 125 to DV.
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');
});

3 Comments

Would also work better if you didnt abbreviate the css key and value you're trying to edit; Its text-decoration and underline.
It wasn;t me but some eejit is just downvoting every answer, mine included.
yea, sorry about that... i know the correct property and value there.. just trying to save a few keystrokes.. sorry for the confusion
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/

1 Comment

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!
-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;
}

2 Comments

-1 the hover event should be applied to the image as per the OP.
No, that's not true. This would only create a hover state if I hovered over the h5 element. I want to hover over the views-field element and have a hover state applied to h5.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.