href from mysql database with jquery

Asked

Viewed 21 times

0

I have a question to solve and I rely on your help 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 ) 


         });


}) 

1 answer

0

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

You take the attribute data as follows:

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

This selector is invalid:

$('a[href=#]')

In this case, the symbol # in quotes:

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

And the variable nome here does not exist (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>
<li style="width:290px; border:#f00 0px solid;">
   <a href="#" class="link" data-text="<?php echo  $n1['nick'];?>">Pronto</a>
</li>

Browser other questions tagged

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