Удаление style и class
Добрый день =)
Есть код html: <p class="text_class" style="font-family:arial">text</p> Как средствами javascript получить: <p>text</p> |
aiaks,
<html>
<head><title>...</title></head>
<body>
<div><p class="text_class" style="font-family:arial">text</p></div>
<script>
window.onload = function () {
alert(document.body.children[0].innerHTML);
document.body.children[0].children[0].removeAttribute("class");
document.body.children[0].children[0].removeAttribute("style");
alert(document.body.children[0].innerHTML);
}
</script>
</body>
</html>
|
Спасибо! :victory:
|
Если требуется просто сбросить стили, то можно также и "обнулить"
<style>
.text_class {
color: green;
}
</style>
<div><p class="text_class" style="font-family:arial">text</p></div>
<script>
window.onload = function () {
alert(document.body.children[0].innerHTML);
document.body.children[0].children[0].style.cssText = '';
document.body.children[0].children[0].className = '';
alert(document.body.children[0].innerHTML);
}
</script>
|
| Часовой пояс GMT +3, время: 15:16. |