I have a problem that I'm trying to solve, the current way of doing it requires that I remove elements.
<div id="toremove">
// some JavaScript here
</div>
So I have a function that does something nice, then when that finishes I'd like it to remove the "toremove"
element. I have looked at the jQuery documentation, similar posts allover the Internet but nothing seems to work.
Here's what I'm doing and have tried:
$("#toremove") = $()
$("#toremove").empty();
$("#toremove").remove();
Nothing seems to work for me, any help is appreciated.
jQuery uses: . append(); and . remove(); functions to accomplish this task. We could use these methods to append string or any other html or XML element and also remove string and other html or XML elements from the document.
HTML DOM Element remove() The remove() method removes an element (or node) from the document.
$('#toremove').remove();
should do what you need. Are you sure there isn't a problem elsewhere in your code?
Example
You can do other of the way to deal with this issue, I will show you I know as following.( please pick anyone up you like)
<html>
<body>
<div id="toremove">
...some javascript here....
</div>
</body>
</html>
<script src="jquery-3.3.1.min.js"></script>
<script>
$('#toremove').html(''); // option 1
$('#toremove').attr('style', 'display:none') // option 2
$('#toremove').attr('style', 'visibility:hidden') // option 3
$('#toremove').remove(); // option 4
$('#toremove').hide(); // option 5
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With