Reputation: 41
I'm trying to make this script for a forum, which allows the use of tags in posts. Unfortunately, we can't use line breaks whenever we write these CSS styles because the form reads them as <br>
's and it screws everything.
They appear like this:
<style type="text/css"><!-- <br>#herp { background: #fff; }<br> --></style>
If we stop the form from reading <br>
's, it would affect the rest of the elements. So we've tried to remove them using this:
var style = document.getElementsByTagName("style"); for(x=1;x<style.length;x++) { style[x].innerHTML.replace(/\<br\>/gi,""); }
...to no avail.
To be honest, I'm not quite sure what kind of entities lie between these style tags. I don't think they're strings, nor are they comments. So the replace() doesn't seem to work.
Any thoughts?
Upvotes: 0
Views: 127
Reputation: 4368
You can get stylesheet object by using document.styleSheets
Try this in console
for(i in document.styleSheets){
if(!isNaN(i)){
document.styleSheets[i].disabled = true;
}
}
Upvotes: 0
Reputation: 1693
var style = document.getElementsByTagName("style");
for(x=1;x<style.length;x++) {
style[x].innerHTML=style[x].innerHTML.replace(/\<br\>/gi,"");
}
Upvotes: 1