2

I have the following code,

<ul class="post-buttons">
    <li>
        <a class="button icon-button thank-icon" title="Thank this post" href="./thank.php?f=12&p=249224"></a>
    </li>

</ul>

and on my javascript I have the following,

var ThankButton = $('div.thank-icon > a').attr('href');
console.log(ThankButton);

but on console log I get ThankButton not defined, what I'm doing wrong here?

Gerhard
  • 6,465
  • 8
  • 52
  • 80
m0b1l3us3r
  • 85
  • 2
  • 11

3 Answers3

5

You have javascript mistake

var ThankButton = $('ul.post-buttons li a.thank-icon').attr('href');
console.log(ThankButton);
Bhavin Solanki
  • 4,656
  • 3
  • 23
  • 45
1

I don't see any div in your code. You can try simply:

var ThankButton = $('a.thank-icon').attr('href');
console.log(ThankButton);
serhiyb
  • 4,638
  • 2
  • 13
  • 24
1

You could do something like,

var ThankButton = $('.thank-icon').attr('href');
console.log(ThankButton);

or

var ThankButton = $('ul li a').attr('href');
console.log(ThankButton);

or

var ThankButton = $('ul li a.thank-icon').attr('href');
console.log(ThankButton);
Ashish Ahuja
  • 4,913
  • 10
  • 51
  • 65