I am basically trying to print the value of a button in the div with list class if the button is selected. Also remove the same value wwhen it is deselected. I am able to print the value successfully but not able to remove it. Could somebody please help me out with it.
var buttonSelect = $(".btn").click(function() {
if ($(this).hasClass('active')){
$(".list").append(this.value + " ")
}
else {
$(".list").remove(this.value)
}
});
thisis the HTML element, and$(this)is the jQuery object. Try to use$(".list").remove($(this))remove()removes an object, if you just want to clear the text you can do$(this).text("")or any of the answers listed belowjquery.remove()removes elements from the DOM, a TextNode is not an element.. however, both are "objects".. so I would refrain from using object as some sort of qualifier here..