javascript - If function doesn't return false? -
javascript - If function doesn't return false? -
i have next click
event:
$('#planung').click(function(){ if($current != $('#planungtext')){ console.log($current); console.log($('#planungtext')); $($current).removeclass('active'); settimeout(function(){$('#planungtext').addclass('active')}, 1000); $current = $('#planungtext'); } });
i used log see contents of variable , '#planungtext'
element. same, if function doesn't work desired, still going it.
$current not set before first time element clicked.
am doing wrong here?
the 2 jquery objects point @ same dom elements, different arrays (jquery objects arrays behind scenes with stuff).
use jquery is
http://api.jquery.com/is/ test if same selector match them:
if(!$current.is('#planungtext')){
the fastest way check "manually" is:
if ($current[0].id !== '#planungtext'){
it mentioned in comment $current jquery variable (good naming standard) undefined
in case every solution posted crash. need initialise $current empty jquery object give consistent behavior (jquery objects should never undefined used that, else need re-wrap it. e.g. $($current)
not recommend solution uninitialised jquery variable):
var $current = $(); // $() returns empty jquery object
javascript jquery
Comments
Post a Comment