Change information with JS-JQUERY

0

I am trying to change a certain value inside my html code, through JS-JEQUERY, but it is not changing, my logic is wrong?

Follow the code:

var valor = "texto";
$('.botao botao-comprar principal grande desativo with-popover').on('click', function () {
   
   $(this).data('data-content', valor);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><ahref="javascript:;" class="botao botao-comprar principal grande desativo with-popover" rel="popover" data-placement="left" data-trigger="hover" data-content="Selecione uma opção de atributo disponível." data-original-title="IMPORTANTE">
  <i class="icon-shopping-cart"></i> Comprar
</a>
    
asked by anonymous 13.12.2018 / 15:59

1 answer

1

If I understand correctly, you are trying to manipulate the date attribute of the button. So, in case you have already used the data method, you do not need to write in it data-content , but only content , so to manipulate an Html element you do not have to put all If you have a class that is already in it, just the first one is enough, if the class is unique, otherwise put a specific $ buy-in type or use a% button) :

var valor = "texto";
$('.botao').on('click', function () {
   
   $(this).data('content', valor);

   console.log('O data-content agora é: ' + $('a').data('content'));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><ahref="javascript:;" class="botao botao-comprar principal grande desativo with-popover" rel="popover" data-placement="left" data-trigger="hover" data-content="Selecione uma opção de atributo disponível." data-original-title="IMPORTANTE">
  <i class="icon-shopping-cart"></i> Comprar
</a>
    
13.12.2018 / 16:22