Let me start by saying that I’m not a JavaScript programer or a jQuery guru by any means, I’m actually just starting with jQuery.
I have the two following jQuery codes:
$('.tipTrigger').hover(function(){
$(this).toggleClass('active').prev('.tipText').stop(true, true).fadeToggle('fast');
});
and
if ($(".tooltip-container").length > 0){
$('.tipTrigger').hover(function(){
$(this).toggleClass('active').prev('.tipText').stop(true, true).fadeToggle('fast');
});
}
Several questions I have about this:
- What is basically the difference between the two codes above?
- What is the meaning of
if ($(".tooltip-container").length > 0){? - Is there a benefit to using the above
if? - What’s more ‘efficient’ from a developer’s stand point? (that is IF something so small would have a considerable performance impact in any way)
Any other comments/help with this simple comparison would be greatly appreciated.
Thanks in advance.
What is basically the difference between the two codes above?
What is the meaning of if ‘($(“.tooltip-container”).length > 0){‘?
Is there a benefit to using the above
if?What’s more ‘efficient’ from a developer’s stand point? (that is IF something so small would have a considerable performance impact in any way)
>
For Further Understanding
tipTextthat comes before current element in dom