Miko Posted March 10, 2011 Share Posted March 10, 2011 Hello, i'm trying to replace a br tag. I have this as code for the moment: var br = document.getElementsByName("br"); br.parentNode.replaceChild(document.createElement("p"), br); but I get this error: "br.parentNode is undefined" Someone knows what I'm doing wrong here? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/230207-replace-element/ Share on other sites More sharing options...
nogray Posted March 10, 2011 Share Posted March 10, 2011 getElementsByName() will return an array of elements. If you only have 1 br in your page, you can access it by br[0]. Otherwise loop over the array and replace all the brs Quote Link to comment https://forums.phpfreaks.com/topic/230207-replace-element/#findComment-1185825 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.