javascript - JQuery Page Number Switcher Bug -


tabs html

<a class="page_prev page_current" href="javascript:;" hidefocus="true" style="outline: none;">     <span>prev</span> </a> <a id="gal_btn_p1" href="javascript:;" class="page-numbers page_current" hidefocus="true" style="outline: none;">1</a> <a id="gal_btn_p2" href="javascript:;" class="page-numbers" hidefocus="true" style="outline: none;">2</a> <a id="gal_btn_p3" href="javascript:;" class="page-numbers" hidefocus="true" style="outline: none;">3</a> <a class="page_next" href="javascript:;" hidefocus="true" style="outline: none;">     <span>next</span> </a> 

jquery code

    var gal_c_page = 1;     var gal_m_page = 3;      $('.tf_pagination a').click(function(e) {         if (!$(this).hasclass('page_current')) {              $('.page_current').removeclass('page_current');             $('#page_' + gal_c_page).hide();              if ($(this).hasclass('page_prev')) {                 if (gal_c_page == '2') {                     $(this).addclass('page_current');                 }                 gal_n_page =  gal_c_page - 1;                 $("#page_" + gal_n_page).show();                 $('#gal_btn_p' + gal_n_page).addclass('page_current');                 gal_c_page = gal_n_page;             } else if ($(this).hasclass('page-numbers')) {                 gal_n_page = $(this).text();                 $("#page_" + gal_n_page).show();                 $(this).addclass('page_current');                 if (gal_n_page == gal_m_page) {                     $('.page_next').addclass('page_current');                 } else if (gal_n_page == '1') {                     $('.page_prev').addclass('page_current');                 }                 gal_c_page = gal_n_page;             } else if ($(this).hasclass('page_next')) {                 if (gal_c_page == gal_m_page + 1) {                     $(this).addclass('page_current');                 }                 gal_n_page = gal_c_page + 1;                 $("#page_" + gal_n_page).show();                 $('#gal_btn_p' + gal_n_page).addclass('page_current');                 gal_c_page = gal_n_page;             }             alert(gal_c_page);         }     }); }); 

the problem

well if jquery code not whole load of crap , on complicated, problem having is;

  • clicking through (1, 2, 3...) - works
  • clicking next through - works
  • clicking number next - variable becomes 11 or 21.

i've included javascript tag question i'm not fussed on how it's done long can in resolving.

i've tried multiple edits whereas code added here current version.

gal_n_page = $(this).text(); give string, , string + number = string, e.g: '1' + 1 = '11'. change gal_n_page = parseint($(this).text(), 10);


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -