$("#whoToFollow").on("click", "p", function() {
const text = $(this).text()
$("div:not(:contains(' + text + '))").remove()
});
I want to remove any divs which does not contain the text in the p tag that was clicked. The above code works if I replace (' + text + ') with the exact text ('david') but does not work when using the text variable. What am I missing here?
$("div:not(:contains('" + text + "'))").remove()You have to escape the"to include your variable