I have a sidebar that populates a ul based via the h3 contents of a clicked div element in the main content of the page.
This (below) is the jQuery I am using to attempt to only show each title once.
The first element clicked on will not be repeated in the sidebar with multiple clicks, but every other clicked div will repeat in the sidebar, including the first div > h3 if another div was clicked first.
console.log shows that title prints out the clicked item but sidebarinsutry only prints out the text of the first li added to the ul.
I want to be remove an li from the ul if the content matches the content of the div >h3 being clicked on. In other words, remove duplicates from the sidebar as they happen.
$(".industries").on('click', function(){
var title = $(this).find('h3').html();
var sidebarindustry = $('.widget-Text_Widget ul').find('.indhandle').find('.sidebar-title').html();
////****!!!!wont work bc they are both type object and reference different objects*****/
var indIteminList = title !== sidebarindustry;
$('.widget-Text_Widget').find('ul').append(indIteminList ? '<li class="indhandle labelsidebar"><span class="sidebar-title">'+ title +'</span> <span class="sidebar-item-remove">x</span></li>') : '';