title: How to make a list item that's clicked on change color?
body: <p>I currently have an UL list structure and i'd like to make the selected item's background change, thus giving confirmation which was selected. I want to do it in a click JQuery method. That's currently the code I have, which select and gets the necessary data, associated with my items in the list. I have configured a CSS for the first child and I want to make the selected item the list's first child, inside this function. The function does a few things, but they're irrelevant to the question, hence why I've removed them.</p>
  <p><a href="https://i.stack.imgur.com/I3G49.png" rel="nofollow noreferrer">Picture of my system</a></p>
  <pre><code>    $(document).on('click', 'li.msg-user-name-wrap', function() {
  
                  clearInterval(loadTimer);
                  var otheridFromSearch = $(this).data('profileid');
                  var searchImage = $(this).find('.msg-user-photo img').attr('src');
                  var searchName = $(this).find('.msg-user-name').text();
                  $('.users-right-pro-pic img').attr('src', searchImage);
                  $('.users-right-pro-name').text(searchName);
                  $('.user-info').attr(&quot;data-otherid&quot;, otheridFromSearch);
                  xyz(useridd, otheridFromSearch, abc);
  
                  $.post('http://localhost/facebook/core/ajax/message.php', {
                      showmsg: otheridFromSearch,
                      yourid: useridForAjax
                  }, function(data) {
                      $('.msg-box').html(data);
                      $('.user-show').empty();
                      $('.top-msg-user-photo img').attr('src', searchImage);
                      $('.top-msg-user-name').text(searchName);
                      scrollItself();
                  })
  
                  if (!intervalId) {
                      intervalId = setInterval(function() {
                          loadMessageFromSearch(useridForAjax, otheridFromSearch);
                      }, 1000);
                      clearInterval(intervalIdtwo);
                      intervalIdtwo = null;
                  } else if (!intervalIdtwo) {
                      clearInterval(intervalId);
                      intervalId = null;
                      intervalIdtwo = setInterval(function() {
                          loadMessageFromSearch(useridForAjax, otheridFromSearch);
                      }, 1000);
                  } else {
                      alert('Nothing found');
                  }
  
              })
  </code></pre>