Methods to delete meta tags: 1. Use the removeChild() method to delete, the syntax is "meta element object.parentNode.removeChild(meta element object)"; 2. Use the remove() method to delete, the syntax is "meta element Object.remove()".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Method 1. Use the removeChild() method to delete the meta tag element
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" id="remove"> </head> <body style="text-align:center;"> <p style="font-size: 19px; font-weight: bold;">单击按钮删除meta元素</p> <button onClick="Fun()">点击这里</button> <p id="DOWN" style="color: green; font-size: 24px; font-weight: bold;"> </p> <!-- Script to remove HTML element --> <script> var down = document.getElementById('DOWN'); var meta = document.getElementById('remove'); //获取meta标签元素对象 function Fun() { meta.parentNode.removeChild(meta); down.innerHTML = "元素被删除!"; } </script> </body> </html>
Rendering:
Method 2. Use the remove() method to delete the meta tag element from the document
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" id="remove"> </head> <body style="text-align:center;"> <p style="font-size: 19px; font-weight: bold;">单击按钮删除meta元素</p> <button onClick="Fun()">点击这里</button> <p id="DOWN" style="color: red; font-size: 24px; font-weight: bold;"> </p> <!-- Script to remove HTML element --> <script> var down = document.getElementById('DOWN'); var meta = document.getElementById('remove'); //获取meta标签元素对象 function Fun() { meta.remove(); down.innerHTML = "meta元素被删除!"; } </script> </body> </html>
Rendering:
[Recommended Study: javascript advanced tutorial】
The above is the detailed content of How to remove meta tag in javascript. For more information, please follow other related articles on the PHP Chinese website!