Change Text in IFrame without JQuery [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Weave: http://kodeweave.sourceforge.net/editor/#f6d9a54288f17fb68a8b234ec364dc41
I love JQuery, I do, but just for fun I'd like to learn how to write the following in pure/vanilla JS.
$("iframe").contents().find("<style>").html(cssEditor.value))

Something like this should work:
document
.getElementsByTagName('iframe')[0]
.contentDocument
.getElementsByTagName('style')[0]
.innerHTML = cssEditor.value;

Use the contentDocument property of the <iframe> DOM object to get the inner document.
You can then call normal methods on it like querySelector.

Related

Manipulating `body` element in React [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 months ago.
Improve this question
Is it advisable to manipulate the parent of the DOM that is body element manually in React just like we do in vanilla JS?
Like is it good practice to do like this because here I am not manually manipulating DOM, but instead manipulating it parent element?
document.body.style.overflow = "hidden"
In my experience: It's ok to do this.
Often this sort of thing is done when opening Modals (like Bootstrap)
It's a valid thing to do.

[WebdriverIO][Typescript] Is it possible to get a custom variable from the browser window? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Hi lets assume i have a custom variable in the browser."Custom variable" Is it possible to get it with webdriverIO with the browser.execute() method?
Yes, it's possible with js.
browser.execute("return a")
Here is the sample I tried in python using js which is equivalent to browser.execute.

How to write JavaScript code to duplicate HTML elements? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Suppose I have an HTML element (like a <div>). Is there a way to duplicate it after a click using JavaScript?
If yes, is it possible to change the content of the duplicated HTML element to something else?
EDIT: Yes, I was asking how to do it as well. Thanks to the guys who answered my question!
You can use Node.cloneNode() on original element, set Elment.innerHTML of cloned node.
a
<script>
var clone = document.querySelector("a").cloneNode();
clone.innerHTML = "b";
document.body.appendChild(clone);
</script>
See clone.
$('a').clone().html("something else");

jQuery, reuse method for many divs [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a CoffeeScript code that looks like this:
if $('#user_address_attributes_country').val() == ""
$('#user_address_attributes_country').val("PL")
Now I want to do the same thing for a few divs but without repetitions.
How can it be done by jQuery?
The reason you can't apply it multiple times is because your trying to apply it to an element which has an id. They are unique. Use classes and do this instead:
if ($('.user_address_attributes_country').val("")) {
$('.user_address_attributes_country').val("PL");
}
Simple demo: JsFiddle

Using CSS in JS [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to change CSS elements depending on situations used in javascript.
an example I had tried was:
if ('image'=="clicked")
{blahblahblah}
'image' would be my div id or div tag in CSS.
I know in Jquery I can use $('#image').click, but I don't think it Jquery will be good for my situation.
Consider document.querySelector. It's powerful, accepting any valid CSS selector. You can even start from another element, such as myElement.querySelector, to only get children of that element that match the selector. Very useful!
Just be aware that IE7 and below do not support this function.
Assuming your id as image
document.getElementById('image').onclick = function() {
alert("button was clicked");
}​;​

Categories