Tweet stuck on first quote

Tweet stuck on first quote
0

#1

Hi all,

I’ve almost finished this project but having one issue. I’ve set my JS to update the twitter link with the generated quote when I click for next quote. However, when I click to tweet it always gives me the first quote that was generated , even tho there’s a new quote on the page generated by the same ‘onclick’ event. Can anyone shed some light on this?


#2

The problem is that with this expression you try to update every link that has exactly https://twitter.com/intent/tweet? in its href attribute:

$("a[href='https://twitter.com/intent/tweet?']")

It works the first time, as it is the href when you load the page. But… When you click on the new quote button, you update this attribute, so your query no longer matches your link. You can give your a tag an id or class to avoid this, or just grab it with $('a'), but what if you add more links later to your page? I hope it helps.


#3

Ah I see ! That’s great zsoltime - it was really annoying me there. Thanks a million. The id route is the best solution so.


#4

No problem and yep, id will be great :wink: