javascript - jQuery displaying NaN -
i'm trying data element in html, jquery "nan" when ask jquery place grabbed data in paragraph tag.
here full code:
$(".next-panel").click(function(event) { var accordion = $(".nav-accordion") var index = accordion.accordion('option','active') var next = index + 1; var panel = $(this).parents('.accordion-panel').next(); var sectiontitle = $(this).parents('.accordion-panel').parents('li').next('li').children('a').attr('data-title'); var sectiondesc = $(this).parents('.accordion-panel').parents('li').next('li').children('a').attr('data-desc'); var sectionpercent = $(this).parents('.accordion-panel').parents('li').next('li').children('a').attr('data-percent'); $('body').animate({ scrolltop: $('#accordion-wrap').offset().top }, 800 ); accordion.accordion('activate', next); panel.removeclass("ui-state-disabled").bind("click"); $('#progress-box h6').text(sectiontitle); $('#progress-box p').text(sectiondesc); $('#percent-bar-inner p').text(sectionpercent); $('#percent-bar-inner').animate({ width: sectionpercent, }, 300); console.log(sectionpercent) event.preventdefault(); return false; });
when use this:
var sectionpercent = $(this).parents('.accordion-panel').parents('li').next('li').children('a').attr('data-percent');
and tell output var to:
$('#percent-bar-inner p').text(sectionpercent);
it gives me:
nan
but when log variable, gives me:
50
which correct value.
why happen , nan mean?!
update
js fiddle examples:
this js fiddle showing working expected:
with these bits of code removed:
var accordion = $(".nav-accordion") var index = accordion.accordion('option','active') var next = index + 1; var panel = $(this).parents('.accordion-panel').next();
and also
accordion.accordion('activate', next); panel.removeclass("ui-state-disabled").bind("click");
Comments
Post a Comment