Javascript To Remove All Hidden Elements But One
Someone helped me find JavaScript code to remove hidden form fields from submission and code that ignores a certain field that I don't want removed (whether it's hidden or not): $(
Solution 1:
$(this).find(":hidden").not('input[name=csrfmiddlewaretoken]').remove();
Or
$(this).find(":hidden").filter(':not(input[name=csrfmiddlewaretoken])').remove();
Or
$(this).find("input[name!=csrfmiddlewaretoken]:hidden").remove();
Solution 2:
$(this).find(":hidden").filter("[name!='csrfmiddlewaretoken']").remove();
Solution 3:
You can pass the this
as a context argument, which will be potentially faster than making a jQuery object from it. The :not()
expression can follow the :hidden
without spaces, meaning that it adds a second condition to the :hidden
selector.
$(":hidden:not(input[name=csrfmiddlewaretoken])", this).remove();
Post a Comment for "Javascript To Remove All Hidden Elements But One"