.live() doesn't work properly
Hi everybody,
I'm trying to use the .live() function but I'm having a trouble. I call some buttons using the $.ajax() method with something like this.
It's on PHP:
foreach($vPerm as $vetPerm){
switch($vetPerm['transacao']){
case "CADASTRAR":
if($vetPerm['permitido'] == true){
$tpl->TRANSACAO = '<button class="fg-button ui-state-default ui-state-active" status="ativo">CADASTRAR</button>';
}else{
$tpl->TRANSACAO = '<button class="fg-button ui-state-default" status="inativo">CADASTRAR</button>';
}
break;
As you can see. I bring those buttons and add in my DOM tree. Perfect. And I can use without any problem the .live() function. But these buttons are separeted by users, and his modules, in other words, each user I have 13 modules and in every module I have 5 buttons. The problem is when I click on the buttons, my function accumulates events, so when I click on the first button of the first module trigger one time, if click on other buttons, trigger on time, but if click again on the first button from the first module, for example trigger twice.
JS:
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
var status = $(this).attr("status");
var pai = $(this).parents().find(".modulo");
var dataPerm = pai.attr("dataMod");
switch(status){
case 'ativo':
var dataPerm = dataPerm+"&perm=0&mudaPerm=true";
$.ajax({
type: 'POST',
data: ({dataPerm: dataPerm}),
url: 'app/proc/usuario/proc-permissao-tipo-usuario.php',
success: function(msg){
alert(msg);
}
});
break;
case 'inativo':
var dataPerm = dataPerm+"&perm=1";
alert('inativo');
break;
}
});
});
</script>
Anyone help me?
p.s: sorry for my bad english.