m0b1l3us3r m0b1l3us3r - 7 months ago 37
Javascript Question

Java script get href

Hi all 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?

Answer

You have java script mistake

var ThankButton = $('ul.post-buttons li a.thank-icon').attr('href');
console.log(ThankButton);