1

I need to remove some part of an innerHTML. I've been trying this for 3 hours now. It seems so simple.

This does work...

var foo = '<div id = "test" class = "hidden" style = "width: 350px"></div>';
alert(foo);
foo = foo.split('id = "test" class = "hidden" ').join('');
alert(foo);

And this doesn't...

var myElement = document.getElementById('kjbggk');

myElement.innerHTML = '<div id = "test" class = "hidden" style = "width: 350px"></div>';
alert(myElement.innerHTML);
myElement.innerHTML = myElement.innerHTML.split('id = "test" class = "hidden" ').join('');
alert(myElement.innerHTML);        
wubbewubbewubbe
  • 711
  • 1
  • 9
  • 20

1 Answers1

1

Click here to go to a related StackOverflow question that may solve your issue.

This question on SO also seems related to your question.

Alternately, have you tried

var myElement = document.getElementById('kjbggk');
alert(myElement.innerHTML);
var foo = '<div id = "test" class = "hidden" style = "width: 350px"></div>';
alert(foo);
foo = foo.split('id = "test" class = "hidden" ').join('');
alert(foo);
myElement.innerHTML = foo;
alert(myElement.innerHTML);
Community
  • 1
  • 1
JoshDM
  • 4,939
  • 7
  • 43
  • 72
  • Thank you. I'm still able to change "test" into "", so the id actually can change. I'll read the links you gave me. – wubbewubbewubbe Jan 24 '13 at 20:12
  • I could not solve it. Started studying the DOM model. I'm almost certain it will solve the problem (although it needs a lot of (simple) code to do so). http://www.w3schools.com/htmldom/default.asp – wubbewubbewubbe Jan 25 '13 at 21:46
  • 1
    Have you considered assigning the value of `innerHTML` to a variable like `foo` in your first example, manipulating `foo`, then assigning `foo` to `innerHTML`? I updated my answer to reflect this suggestion. – JoshDM Jan 25 '13 at 23:04
  • yes, yes, tried, but doesn't work. But thank you for the suggestion. But the DOM model is going to do the trick. Start working on that today. – wubbewubbewubbe Jan 27 '13 at 10:46