Clear data from getElementById innerHTML? [duplicate] - javascript

This question already has answers here:
How do I clear the content of a div using JavaScript? [closed]
(2 answers)
Closed 2 years ago.
document.getElementById('test').innerHTML = '<h1>Hello World</h1>';
Is there anyway that I can remove everything the code above put between two HTML tags?

I gather you want to remove the text between the <h1> and the </h1>. Simple:
const test = document.getElementById('test');
const child = test.firstChild;
child.innerHTML = "";

Related

How to add “ ?&max-results= ” after the /search/label/LABEL_NAME in blogger use javascript [duplicate]

This question already has answers here:
How to update (append to) an href in jquery?
(4 answers)
Append URL parameter to href with JavaScript
(2 answers)
How to append to an anchor's href attribute with JavaScript but not affect query string?
(3 answers)
Closed 2 years ago.
I want to change all the labels links and have a specific number to access it in blogger using JavaScript automatically
An illustrative example
../search/label/Label_name and add max-results=7 after "label name"
how i can do it .. i want help and thank you.
Something like this should do the trick. If you have further questions feel free to ask them :)
var x = document.querySelectorAll("a");
x.forEach(function(element){
var link = element.href;
console.log(link)
element.href = link + "?max-results=7";
console.log(element.href);
});
Example link

Show or hide class as a parameter [duplicate]

This question already has answers here:
How do I concatenate a string with a variable?
(5 answers)
Closed 3 years ago.
This is basic ,
I can show or hide a class with :
$('.blink').show();
but I would like to do the same with a parameter so
var a = "blink";
$(a).show();
will not work obviously and I couldn't find the keywords to look for this in google.
You need to append a dot when you use that variable so that the $ will consider it as a class selector:
var a = "blink";
$('.'+a).show();

How can I use js var in html? [duplicate]

This question already has answers here:
How to display JavaScript variables in a HTML page without document.write
(9 answers)
Closed 4 years ago.
I'm actually trying to use a js var in my html code like this :
In javascript code :
var test = 'This is a test';
And in the html :
<p>display var test here</p>
How can I display the value of my js var in html like this ?
HTML:
<p id="paragraph"></p>
JavaScript:
var test = 'This is a test';
document.getElementById('paragraph').innerHTML = test;

How do I translate HTML code into normal text with javascript? [duplicate]

This question already has answers here:
HTML Entity Decode [duplicate]
(17 answers)
Closed 6 years ago.
I want to translate an input from an API like this
<p>Communication that doesn’t take a chance doesn’t stand a chance.</p>
into something like this
"Communication that doesn’t take a chance doesn’t stand a chance."
I understand that html could translate this but I don't know how to translate this directly for use in javascript
Insert it into an element as HTML, and read it back out as text.
var elt = document.createElement('div');
elt.innerHTML = apiResponse;
alert(elt.textContent);

How to remove dom element? [duplicate]

This question already has answers here:
JavaScript DOM remove element
(4 answers)
Closed 8 years ago.
Ok I've been so spoiled with Jquery that I don't even know how to remove an element anymore with plain Javascript.
So I have this which I would like to remove with Javascript.
Any help appreciated.
Try this
function RemoveElement(elemID) {
var elem = document.getElementById(elemID);
if (elem.parentNode) {
elem.parentNode.removeChild(elem);
}
}
Node.removeChild is the method, see documentation here: https://developer.mozilla.org/En/DOM/Node.removeChild
Example:
var parent = document.getElementById("mydiv");
var child = document.getElementById("other");
parent.removeChild(child);
like:
container.removeChild(child);

Categories

Resources