1

with this code read "pnotify-no-title" and after click show Check Text with bg-primary Class; now i need after one click show Check text with bg-primary and after next click show check2 text with bg-primary2 class and again after next click show check text with bg-primary class

  $('#pnotify-no-title').on('click', function () {
    new PNotify({
        text: 'Check',
        addclass: 'bg-primary'

    });
});
Arun Xavier
  • 712
  • 8
  • 43
Sae Edx
  • 13
  • 4

3 Answers3

0

Try this:

$('#pnotify-no-title').click(function() {
  var clicks = $(this).data('clicks');
  if (clicks) {
    new PNotify({
        text: 'Check',
        addclass: 'bg-primary'

    });
  } else {
    new PNotify({
        text: 'Check',
        addclass: 'bg-primary2'

    });
  }
  $(this).data("clicks", !clicks);
});

Main Topic

JSFiddle

Community
  • 1
  • 1
Pedram
  • 14,199
  • 8
  • 38
  • 69
  • this is exactly what you wanted, odd and even click, what you have expect? @SaeEdx , anyway, it doesn't matter anymore, you got you answer. – Pedram Mar 02 '16 at 06:14
0

use jquery toggleClass function.. http://www.w3schools.com/jquery/html_toggleclass.asp

Asad
  • 2,760
  • 7
  • 18
  • 56
0

I believe you need to record alternate clicks. One easy way is to add a class to the object to record which click it is

  $('#pnotify-no-title').on('click', function () {
    var $this = $(this);
    new PNotify({
        text: $this.hasClass('odd-click') ? 'Check2' : 'Check',
        addclass: $this.hasClass('odd-click') ? 'bg-primary2' : 'bg-primary'

    });

    $this.toggleClass('odd-click');
});
Aukhan
  • 481
  • 4
  • 9