Development HTML jQuery

How to create a proper click event in js, jquery, html

So as an assignment I need to create a barebones twitter clone. I was given a script that creates random tweets from four users and to display them I’m simply using an interval. My issue is that one of the condition requires that if the user clicks on one of the usernames, the website should show that users tweet history. The tweets are all stored inside the generator file. I have literally been trying for over a day to get a dynamic click script to run. I every time a tweet gets appended to the website it has a class of the users name. The closest I have gotten in terms of logic was to put an onclick=functionName(userclass) inside the anchor of my username. But it is out of scope. I’m pretty new at html/jquery. In fact it is my first week so I have been reading up for hours and you all know how it is when you start learning this stuff. The more you read, the more questions you have. Hope somebody can shine some light

Here’s the code:

<!DOCTYPE html> <html>   <head>

    <link rel="stylesheet" href="style.css">
    <script src="jquery.js"></script>
    <script src="data_generator.js"></script>
    <script src="history.js"></script>   </head>

    <img class="bird" src="icon.png">
      <span class='title' id="top">TWIDDLER (def not Twitter)</span>

        var $body = $('.tweets');
        var index = 0;
          var tweet = streams.home[index];
          var $tweet = $('<div></div>');
          var hypername = tweet.user; 
          var $username = $("<a onclick='gethistory("+hypername+")' href='#top' class='"+hypername+"'><span></span></a>");
          var $endline = $('<br>');
          var time = tweet.created_at.toLocaleTimeString();
          $tweet.text(tweet.message + ' | ' + tweet.created_at.toLocaleTimeString());
          $username.text('@' + tweet.user + ': ');
          // console.log($tweet);
          // var testname = $('<h6></h6>').text('***'+hypername+'***').appendTo($body);
          index += 1;
        }, 2000);
         var gethistory = function(name) {
           console.log("I clicked it");
          for (var i = 0; i < streams.users[name].length; i++) {
            var tweethist = streams.users[name][i];
            var $tweethist = $('<div></div>');
            var $endline = $('<br>');
            $tweethist.text(tweet.message + ' | ' + tweet.created_at.toLocaleTimeString());

    <section class="row">

        <div class="column1 tweets left"><h2>Tweeds</h2></div>

        <div class="column2 right" id="history"></div>


    <!-- <section>
      <audio controls autoplay src="song.mp3"></audio>
    </section> -->



Leave a Reply

Your email address will not be published. Required fields are marked *