MacFerret
MacFerret

Reputation: 57

jQuery .hover() and .click() not working

I'm trying to add a simple hover and click function to a part of my page and it's not working. I've done this hundred of times with no problem but this time is different and I can't find out why?

HTML:

<div class="description">
    <div id="wrapper">
        <p>bla bla bla</p>
        <div class="linkDesc">
            <a href="#">bla bla bla</a>
        </div>
        <div class="plusSign">&nbsp;</div>
    </div>
</div>

jQuery:

jQuery(document).ready(function () {

    $('#wrapper').hover(function () {
        $('this').addClass('hover');
    }, function () {
        $('this').removeClass('hover');
    });
    $('#wrapper').click(function(e) {
        e.preventDefault();
        var urlLocation = $('this').find('.linkDesc').children('a').attr('href');
        window.location = urlLocation;
    });
});

Upvotes: 1

Views: 288

Answers (3)

Epsil0neR
Epsil0neR

Reputation: 1704

if you need only add/remove class, then you can set hover with css:

#wrapper:hover {
    background: red;
}

Upvotes: 0

YardenST
YardenST

Reputation: 5256

Replace $('this') with $(this)

Upvotes: 0

Sushanth --
Sushanth --

Reputation: 55740

$('this')   // You have enclosed it as as a string
            // It will try to look for tagName called this

should be

$(this)    // Removing the Quotes should work

Only legal TagNames , classNames , psuedo Selectors and Id's are supposed to be enclosed in Quotes..

Check Fiddle

Upvotes: 7

Related Questions