Search code examples
javascriptjquerytwitter

setting twitter timeline href


I am trying to dynamically set the href field on my twitter timeline using javascript or jquery how can I do this?

 <a class="twitter-timeline" id="twitter" data-lang="en" data-theme="dark" data-link-color="#19CF86" href=""; data-chrome="noheader, nofooter, noborders, noscrollbar,transparent">Tweets by me</a>

Solution

  • Use setAttribute function. It sets an attribute of the selected element to whatever value provided by the user

    var link="www.link.com";
    document.querySelector("#twitter").setAttribute("href",link)
    console.log(document.querySelector("#twitter").getAttribute("href"))
    <a class="twitter-timeline" id="twitter" data-lang="en" data-theme="dark" data-link-color="#19CF86" href=""; data-chrome="noheader, nofooter, noborders, noscrollbar,transparent">Tweets by me</a>