swap the attribute value with jQuery

Asked

Viewed 343 times

2

I got the following js:

  $("a.bloqDesbloq").click(function() {

         $.post ("../_requeridos/alteraAdministrador.php", {

             idAdministrador   : $(this).attr('idAdmin'),
             bloq              : $(this).attr('bloq')

         }, function(_retorno){

              retorno = JSON.parse(_retorno);


              if (retorno[1] == "OK") {

                  url      = $("a[idAdmin='" + retorno[3] + "']").find('img')
                  bloqueio = $("a[idAdmin='" + retorno[3] + "']")

                  if (retorno[2] == "s")  
                      url.prop("src",'_img/desbloquear.png'),
                      bloqueio.prop('bloq','n')

                  if (retorno[2] == "n")  
                      url.prop("src",'_img/bloquear.png'),
                      bloqueio.prop('bloq','s')

                  //location.reload();

              } else {

                  alert("Erro no bloqueio");

              }

           }
          );

          return false;

  });

That part of the code,

          if (retorno[1] == "OK") {

              url      = $("a[idAdmin='" + retorno[3] + "']").find('img')
              bloqueio = $("a[idAdmin='" + retorno[3] + "']")

              if (retorno[2] == "s")  
                  url.prop("src",'_img/desbloquear.png'),
                  bloqueio.prop('bloq','n')
              if (retorno[2] == "n")  
                  url.prop("src",'_img/bloquear.png'),
                  bloqueio.prop('bloq','s')

              //location.reload();

          } 

It aims to change 2 things:

A) A image of link

B) A attribute called Bloq which receives 2 possible values 's' or 'n';

To image is changing correctly. But the attribute Bloq is not.

Where am I going wrong?

Here is the HTML

<a class='bloqDesbloq' idAdmin=<?php echo $administrador->getIdAdmin(); ?> bloq='s'>
   <?php echo $imagem; ?>
</a>

That changes as you read in the bank

1 answer

2


Try using attr instead of prop:

url.attr("src",'_img/desbloquear.png'),
bloqueio.attr('bloq','n')
  • 1

    Exactly that. It worked out! attr for HTML prop is only in DOM

Browser other questions tagged

You are not signed in. Login or sign up in order to post.