mysql database href with jquery

0

I have a question to solve and I count on the help of you this code does not display the contents of the variable.

<li style="width:290px; border:#f00 0px solid;"><a href="#" class="link"   data-text="<?php echo  $n1['nick'];?>"  >Pronto</a></li>

$(document).ready(function(){
 $(".link").click(function(){
         var nomes = $(this).text("data-text");
         alert(nomes);       
         $('a[href=#]').attr('href', nome ) 


         });


}) 
    
asked by anonymous 02.04.2018 / 02:48

1 answer

0

By the code content, you want to get the value of the data-text attribute and play to the href of the link. But there are 3 problems:

You get the data attribute as follows:

var nomes = $(this).data("text");

This selector is invalid:

$('a[href=#]')

In this case, you should put the symbol # in quotation marks:

$('a[href="#"]')

And the nome variable does not exist here (maybe just a typo):

$('a[href=#]').attr('href', nome )

The corrected code looks like this:

$(document).ready(function(){
   $(".link").click(function(){
      var nomes = $(this).data("text");
      alert(nomes);       
      $('a[href="#"]').attr('href', nomes ) ;
   });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><listyle="width:290px; border:#f00 0px solid;">
   <a href="#" class="link" data-text="<?php echo  $n1['nick'];?>">Pronto</a>
</li>
    
02.04.2018 / 03:36