Does jQuery .remove() clear out loaded javascript when it is used to remove a script tag?

Asked
Active3 hr before
Viewed126 times

4 Answers

remove
90%

Does the javascript itself remain in memory or is it cleaned?,As the title says, if I remove a script tag from the DOM using:,However, as stated above, does using jQuery's .remove() actually clean out the javascript from memory or does it simple remove the <script> element from the DOM?,I am moving some common javascript interactions from static script files into dynamically generated ones in PHP. Which are loaded on demand when a user requires them.

As the title says, if I remove a script tag from the DOM using:

$('#scriptid').remove();
load more v
88%

Does the javascript itself remain in memory or is it cleaned?,As the title says, if I remove a script tag from the DOM using:,The javascript is appended with an ID and I also remove this from the DOM via the same method.,The javascript is executed automatically upon insertion and the dynamic dialog opens up.

HTML:

<div id="output"></div>

<script id="yourDynamicGeneratedScript">
  function test(n) {
    $output = $("#output")
    $output.append("test " + n + "<br/>")
  }
  test(1);
</script>
load more v
72%

The jQuery remove() method also accepts one parameter, which allows you to filter the elements to be removed.,If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:,The following example removes all <p> elements with class="test":   ,For a complete overview of all jQuery HTML methods, please go to our jQuery HTML/CSS Reference.

$("div").();
65%

We can fetch the third list item using the native JavaScript getElementById() function, then remove it from a jQuery object:, selection Type: jQuery An existing jQuery object to match the current set of elements against. , version added: 1.4.not( selection ) selection Type: jQuery An existing jQuery object to match the current set of elements against. ,As of jQuery 1.4, the .not() method can take a function as its argument in the same way that .filter() does. Elements for which the function returns true are excluded from the filtered set; all other elements are included.

<ul>
   <li>list item 1</li>
   <li>list item 2</li>
   <li>list item 3</li>
   <li>list item 4</li>
   <li>list item 5</li>
</ul>
load more v

Other "remove-undefined" queries related to "Does jQuery .remove() clear out loaded javascript when it is used to remove a script tag?"