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?

2

3 Answers 3

5

You have javascript mistake

var ThankButton = $('ul.post-buttons li a.thank-icon').attr('href');
console.log(ThankButton);
Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.