Though the title seems straight forward and simple, what I am trying to do is a little bit more than it seems.
What I have is a search box to search for users on my website, to send a message to. It returns a list of users and you then click on the user(s) that you want to send a message to. Upon clicking on said user(s), I append the user in a li (it’s a contentEditable div by the way), and then allow for the user to continue searching for additional users. This all works how I want it to, what I am trying to do now is to remove the plain text from the search box.
so if someone types say, “Rober” and then clicks the user, “Robert Smith”, it should remove all plain text that is not wrapped in a li element.
I believe it would be something along the lines of say:
$("div.search").clone().children().remove().end().text();
I use this to filter the li text and such out when searching.
In a non working example of usage, I would say it should be something like this:
var text = $("div.search").clone().children().remove().end().text();
$("div.search").find(text).notIn("li").remove();
Edit
Rather than searching for the exact text to remove, it would probably be better and easier to just rmeove all text that is not wrapped in an li element.
1 Answer