I want to click on an item in the removeFood div and have it match to the item in the text area newFoodName1
$(".removeFood").click(function() {
var removedFood = ($(this).children('.dailyItem').text())
$(this).text('')
var selectedFood = $("#newFoodName1").text();
console.log(removedFood + selectedFood)
if (removedFood == selectedFood) {
console.log('They Match')
} else {
console.log('they dont match')
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='removeFood'>
<p class='dailyItem'>
Eclair
<i class="fas fa-trash-alt"></i>
</p>
</div>
<textarea id='newFoodName1'>Eclair</textarea>
In the console this logs Eclair Eclair However the if statement says they do not match. What am I missing?
Aucun commentaire:
Enregistrer un commentaire