This question already has answers here:
How to pick element inside iframe using document.getElementById
(6 answers)
Closed 7 years ago.
In my javascript code, I want to retrieve the value of a TAG placed in page_1 (which id is: "token"), i've tried the following but it does not work:
<iframe id="Myiframe" src="http://page_1">
<script>
doc = document.getElementById('Myiframe');
value = doc.getElementById("token").value;
</script>
Any idea?
document.getElementById("myText").defaultValue
Related
This question already has answers here:
How to get value of a div using javascript
(7 answers)
Why does jQuery or a DOM method such as getElementById not find the element?
(6 answers)
Closed 1 year ago.
I'm trying to learn innerHTML commands, but it's just showing me "Author: " text.
HTML side
<h1 id="author">Author: </h1>
<p>Sabir Türkleri'nin ve Batı Göktürk boylarının devamı olan Hazarlar, Göktürk birliği döneminde Göktürklerin Batı kanadını oluşturmaktaydı.</p>
</body>
JS side
var content= "Ensar Ergok";
document.getElementById("author").value=content;
You need to use innerText, textContent or innerHTML instead of value.
This question already has answers here:
Do DOM tree elements with IDs become global properties?
(5 answers)
Why don't we just use element IDs as identifiers in JavaScript?
(5 answers)
Is there a spec that the id of elements should be made global variable?
(5 answers)
Automatically created variables from ids in JS? [duplicate]
(6 answers)
Why is document.getElementById not needed? [duplicate]
(1 answer)
Closed 2 years ago.
I just noticed, its not necessary anymore in Chrome to select elements that have an id e.g with getElementById, you can directly call that element with its id name... e.g "para1" in this example:
<head>
<title>getElementById Beispiel</title>
<script>
function changeColor(newColor) {
para1.style.color = newColor;
}
</script>
</head>
<body>
<p id="para1">Irgendein Text</p>
<button onclick="changeColor('blue');">Blau</button>
<button onclick="changeColor('red');">Rot</button>
</body>
is there any more specification on this? didn't find anything about it on the internet..
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
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:
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];