-6

I'm using:

$('#btnEmpresarial').attr('onclick','').unbind('click');

To disable a read by javascript..

Now I needed to activate the onclick after the end of the function.

Does anyone know to disable and enable the onclick of a li?

fmsf
  • 36,317
  • 49
  • 147
  • 195
Giovane Bueno
  • 23
  • 1
  • 9
  • 2
    Alguém sabe desabilitar e habilitar o "onclick" de um "li"? what does it mean ? – Suresh Atta May 06 '13 at 18:58
  • The code before doesn't make sense either. But [the console](https://developers.google.com/chrome-developer-tools/docs/console) should show an error. – Denys Séguret May 06 '13 at 18:59
  • I don't speak Italian (Spanish?) but I think it means "Does anyone know how to disable the behaviour of `onclick` on the li" – MarioDS May 06 '13 at 18:59
  • @MarioDeSchaepmeester I speak Italian, that's not Italian... – Denys Séguret May 06 '13 at 18:59
  • You should really formulate your questions a bit better. I speak semi-fluent drunkanese and jibberish, but I have clue what you're asking... – DeeDub May 06 '13 at 19:00
  • Google says its portuguese https://translate.google.com/?rlz=1C1CHMO_enUS532US532&q=Algu%C3%A9m+sabe+desabilitar+e+habilitar+o&bav=on.2,or.r_qf.&bvm=bv.45960087,d.Yms&biw=1600&bih=762&um=1&ie=UTF-8&hl=en&sa=N&tab=wT#auto/en/Algu%C3%A9m%20sabe%20desabilitar%20e%20habilitar%20o%22onclick%22%20de%20um%20%22li%22 – hop May 06 '13 at 19:01
  • possible duplicate of [Disabling/Enabling Jquery onClick Functions](http://stackoverflow.com/questions/13054821/disabling-enabling-jquery-onclick-functions) – Denys Séguret May 06 '13 at 19:02
  • it is brasilian portuguese btw – fmsf May 06 '13 at 19:32
  • Sorry! I am newbie in stack overflow. – Giovane Bueno May 08 '13 at 17:42

1 Answers1

2

You just need to do:

$('li.something').unbind('click'); // to disable

To enable you need to rebind the function

$('li.something').bind('click', function() { ...

I don't know what you want to do, but if you actually want to unbind/bind the event like an (on/off) then you should store the function and just pass it in the bind.

Like:

function foo(){ ... }

$('li.something').unbind('click'); // to disable
$('li.something').bind('click', foo);
fmsf
  • 36,317
  • 49
  • 147
  • 195