This question already has answers here:
Remove all content using pure JS
(11 answers)
Closed 8 years ago.
how to clear all of document text with java script ?
I tried this but this code clear only body element :
document.body.innerHTML="";
simply you can use
document.body.innerText = '';
to remove the entire page text
Related
This question already has answers here:
How to change a text with jQuery
(8 answers)
Closed 6 years ago.
I have a javascript code. The code always appends some text to an old one. But I dont want that the text is attached to the old text. Instead, I want that it replaces the old text.
Here is the code line:
$("#werkstatt").append("Text");
How can I do that?
Thank you very much!
You have to use empty() method.
$("#werkstatt").empty().append("Text");
or simply you should use .text() method.
$("#werkstatt").text("Text");
This question already has answers here:
Access the css ":after" selector with jQuery [duplicate]
(3 answers)
Closed 8 years ago.
I can get css of an element in an iframe by this way:
var bg_color = $('iframe.#myIframe').contents().find('div#someId').css('background-color');
but I can't get:
var bg_color = $('iframe.#myIframe').contents().find('div#someId:hover').css('background-color');
So, how can I get css of a hover element in an iframe (same domain)? Please help me! Thanks!
This cannot be done, the iFrame is literally a window to another webpage, therefor it is not in your DOM, and not accessible by your jquery
This question already has answers here:
How can I add "href" attribute to a link dynamically using JavaScript?
(9 answers)
Closed 8 years ago.
In my site I have one div like this
<div class="yjme_item_in yjmeitem29">
inside this div there is a link and I would like to replace the href of it, introducing www.google.com.
Any ideas ?
I have tried this with no luck
var a = document.getElementsByClassName("yjmeitem29")[0];
a.setAttribute("href", "www.google.es");
Try this
a.childNodes[0].setAttribute("href", "www.google.es");
This question already has answers here:
Remove all child elements of a DOM node in JavaScript
(37 answers)
Closed 9 years ago.
I found some jQuery code to clear the contents of a div:
$('#masterdiv').empty();
Is there any similar way to do this in raw javascript, without jQuery or any other library?
This code will work.
while (myNode.firstChild) {
myNode.removeChild(myNode.firstChild);
}
Mention the id of the tag on myNode for which you want to remove the inner child.
Please have a look on
http://jsfiddle.net/2dJAN/19/
<div class="btn-post">123</div>
$(".btn-post").html("")
This question already has answers here:
How to get the entire document HTML as a string?
(16 answers)
Closed 5 years ago.
I know there's a way to do this, but I cannot recall how.
How do I go about grabbing the HTML element (top-most element in the DOM), using plain JavaScript?
Use document.documentElement.
See the docs: https://developer.mozilla.org/en-US/docs/Web/API/Document/documentElement
var html = document.getElementsByTagName('html')[0];