It's (not, see after the rule) because strings are immutable, I think, and you're setting the innerHTML of the parent element to be the exact same string you retrieved from it earlier.
Instead, I'd suggest:
var firstname = document.getElementsByTagName('input')[0],
parentHTML = firstname.parentNode.innerHTML,
newHTML = parentHTML.replace(/>s+</g,'');
firstname.parentNode.innerHTML = newHTML;
console.log(parentHTML, newHTML, (parentHTML == newHTML));
JS Fiddle demo.
With regards to the comment from jfriend00 (below), it seems the regular expression was the problem, the
didn't match the supplied pattern, that being the case, the following amendment satisfies teh requirements:
var firstname = document.getElementsByTagName('input')[0],
parentHTML = firstName.parentNode.innerHTML;
parentHTML = parentHTML.replace(/>s+</g, "><");
firstName.parentNode.innerHTML = parentHTML;
console.log(firstname, parentHTML);?
JS Fiddle demo.
References:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…