Reputation: 57
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"> </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
Reputation: 1704
if you need only add/remove class, then you can set hover with css:
#wrapper:hover {
background: red;
}
Upvotes: 0
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..
Upvotes: 7