Jump to content
Day

nextSibling not working after I cloneNode

Recommended Posts

I have a script that is using cloneNode to add fieldsets to a form. After I use cloneNode, I'm attempting to search through the new node's children to change id attributes, however nextSibling is returning an empty text node instead of the fieldset.After the first one is cloned, the and I clone the second, nextSibling begins to return a fieldset. Im not sure why the first one won't work.Can anyone offer some insight?

Share this post


Link to post
Share on other sites

depending on browser any newline (return carriage) or space will be treated as text node and nextSibling will count that as sibling, use .children() instead, it will only look at elements and ignore text nodes completely.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...