[Solved] Why is my JavaScript if condition not working? October 13, 2022 by Kirat use $.trim like bellow $("ul > li > a").click(function() { var value = $(this)[0].innerText; console.log(value); if($.trim(value) == "Gallery") { console.log("a"); } else { console.log("b"); } }); 5 solved Why is my JavaScript if condition not working?