How can I reset after append() or before()? Please help. Many thanks in advance.
if((#tag_id).text() == 'something'){
$(#tag_id).before("x");
}
// I want to reset the #tag_id to empty
$(#tag_id).val(''); // this doesn't work
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your code example uses
.before(). In this case, it would be better if.before()was given an element aroundxinstead of just the text.Then you could do this:
Remember that using
.before()does not place anything inside the#tag_id, but instead places it before the#tag_id.If you meant for the content to go inside
#tag_idbut at the beginning, you would use.prepend().If your code is using
.append(), one option would be to keep a reference to the element you’re appending, and use that to remove it later.Then you can remove it via the same reference.