[wp-trac] [WordPress Trac] #61721: Filters on pattern archive page not working

WordPress Trac noreply at wordpress.org
Mon Jul 22 07:17:07 UTC 2024


#61721: Filters on pattern archive page not working
-------------------------+-------------------------------------------------
 Reporter:               |       Owner:  (none)
  gaeldenysiak           |
     Type:  defect       |      Status:  new
  (bug)                  |
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Customize    |     Version:  6.6
 Severity:  blocker      |  Resolution:
 Keywords:  needs-patch  |     Focuses:  javascript, administration,
                         |  template
-------------------------+-------------------------------------------------

Comment (by flutterdevpro):

 To fix this error, you need to ensure that the element you're trying to
 remove is actually a child of its parent element. Here are some steps you
 can take:

 **. Check the Parent-Child Relationship:
 **Make sure the element you're trying to remove is indeed a child of the
 parent node. You can do this by checking the DOM structure or using
 JavaScript to confirm the relationship.


 {{{
 let parent = document.getElementById('parent-element-id');
 let child = document.getElementById('child-element-id');

 if (parent.contains(child)) {
     parent.removeChild(child);
 }
 }}}

 **Update Your Selector Logic:
 **Verify that your selectors are correctly identifying the elements you
 want to work with. Sometimes, a slight change in the DOM structure can
 cause your selectors to fail.

 **Ensure the Element Exists:
 **Before trying to remove an element, check if it exists in the DOM.



 {{{
 let child = document.getElementById('child-element-id');

 if (child) {
     child.parentNode.removeChild(child);
 }
 }}}

 **Debugging:
 **Use console.log() to print out the elements you're working with to
 ensure they are what you expect.



 {{{
 let parent = document.getElementById('parent-element-id');
 let child = document.getElementById('child-element-id');
 console.log(parent, child);

 if (parent && child) {
     parent.removeChild(child);
 }
 }}}

 **Wrap Your Code in a Try-Catch Block:
 **This will help you catch any errors and log them, making it easier to
 debug.


 {{{
 try {
     let parent = document.getElementById('parent-element-id');
     let child = document.getElementById('child-element-id');

     if (parent.contains(child)) {
         parent.removeChild(child);
     }
 } catch (error) {
     console.error('Error removing child element:', error);
 }
 }}}

 By following these steps, you can ensure that your code only attempts to
 remove elements that are actually children of the specified parent,
 preventing the DOMException error.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61721#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list