Yii Framework Forum: Jquery On And Off - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Jquery On And Off Rate Topic: -----

#1 User is offline   aslan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 02-April 12

Posted 10 October 2012 - 04:54 PM

hi, i dont know whether it is appropriate to post here, but... i need your help!

i get a string from back-end php via ajax, and write it in a div:
$.ajax ({
...
  success: $('.container').html(str);
...


the 'str' above like:

<span class='tag'>a</span>
<span class='tag'>b</span>


so, after the success of the ajax, i can get:

<div class='container'>
  <span class='tag'>a</span>
  <span class='tag'>b</span>
</div>


i also bind a handler to the click event on the span:

$('.container').on({
click: function(){

$(this).addClass('label'); // this works well

//////// here is the problem !!!!
//////// $(this).off(....) -- this is wrong
//////// $('.container').off('click', $(this)) -- also wrong
//////// how to use 'off' to unbind the 'click' event ????

...

},
...

}, '.tag');


so, as you see above. how can i unbind this 'click' event, please?
0

#2 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,694
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 10 October 2012 - 06:03 PM

The simplest way is to use 'one' instead of 'on', so the event will fire only once.
God is real unless declared as integer
0

#3 User is offline   aslan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 02-April 12

Posted 10 October 2012 - 06:21 PM

View PostORey, on 10 October 2012 - 06:03 PM, said:

The simplest way is to use 'one' instead of 'on', so the event will fire only once.



Hi thanks for your reply.

in 'container' are 2 'span', so if i use 'one' instead of 'on', the 'click' event will be unbinded from both the spans, but what i want to do is to unbind 'click' event only from the 'span' clicked.
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,082
  • Joined: 16-February 11
  • Location:Japan

Posted 10 October 2012 - 10:12 PM

What about this?
<div class='container'>
  <span class='tag clickable'>a</span>
  <span class='tag clickable'>b</span>
</div>


$('.container').on('click', '.clickable', function() {
  $(this).addClass('label');
  $(this).removeClass('clickable');
});


No need to call jQuery.off() ...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users