I’m trying to create the rough equivalent of the “removeFormat” command for Safari.
Right now I can modify this to remove the bold or italic tags applied to text, but not both at once.
function RemoveElement (element)
{
while (element.firstChild)
{
element.parentNode.insertBefore (element.firstChild, element);
}
element.parentNode.removeChild (element);
}
function RemoveBold ()
{
var boldTag = document.getElementsByTagName ("b");
var italicTag = document.getElementsByTagName ("i");
for (var i = 0; i < boldTag.length; i++)
{
var boldTags = boldTag[i];
}
for (var a = 0; a < italicTag.length; a++)
{
var italicTags = italicTag[a];
}
if (boldTag||italicTag)
{
RemoveElement (italicTags, boldTags);
}
}
Thanks in advance
You seem to have messed up your loops:
boldTaganditalicTagare live NodeListsboldTagsanditalicTagscontain the last item of the respective lists (or are still undefined)RemoveElementfunction with two arguments, while it has only one parameter.Just use this: