Hi im using this code for a list of links that have an animation on their padding. I wanted when i clicked on it to keep that padding and not animate back to its original position. What i dont understand are two things. “if (!$(this)” that part of code and how when i dont have a class of current on any link does it find any? Thanks so much!
$(function() {
$('#secondary_content_what_we_do li a').hover(function() {
if (!$(this).hasClass("current")) {
$(this).stop().animate({
"paddingLeft": "10px"
}, 400).addClass('column_hover');
}
}, function() {
if (!$(this).hasClass("current")) {
$(this).stop().animate({
"paddingLeft": "0px"
}, 'slow').removeClass('column_hover');
}
});
$('#secondary_content_what_we_do a').click(function() {
$('a').removeClass('column_active').removeClass("current");
$(this).addClass('column_active').addClass("current");
$('#secondary_content_what_we_do li a').trigger('mouseleave');
var url = $(this).attr('href');
$('#loading_content').hide().load(url).fadeIn(1000);
return false;
});
})
UPDATE
For some reason i cant comment. I understand now, but i dont have a class current in my css so i dont know how that line helps.
This statement:
Is doing several things. It’s wrapping the
thisvariable (which in this case refers to the element that was hovered over) in a jQuery object (using$(...)), and then calling thehasClass(...)method on it, and then notting (!) the result. The statement reads “If the element that was hovered over does not have the class “current” then execute the code within the block“As for the second part of your question, I think you’re referring to this line:
And how it works if the anchor selected doesn’t have a class of
current. If theaelement selected has nocurrentclass, the statement will have no effect (Please let me know if this isn’t what you’re asking).