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
Related
This question already has answers here:
Why does jQuery or a DOM method such as getElementById not find the element?
(6 answers)
Closed 7 days ago.
I'm trying to get an element which is added by an external application. The only way I can get this specific element is by the data-i18n-key attribute which I thought I can grab like any data attribute so something like this.
The code:
const buttons = document.querySelectorAll('[data-i18n-key="sdk.seamless_product_reward.paid_items_required"]');
console.log(buttons.length);
<span class="lion-reward-item__redeem-button-text lion-loyalty-page-reward-item__redeem-button-text" data-i18n-key="sdk.seamless_product_reward.paid_items_required">Paid items required</span>
However, this doesn't return anything. Any ideas how to do this?
Of course, Barmer is absolutely right. Your code works. The problem will be that your JS is initialised before the DOM has finished loading. Pack your JS above the closing body tag.
This question already has answers here:
Getting the parent div of element
(7 answers)
Add CSS attributes to element with JavaScript
(5 answers)
Set CSS property in JavaScript?
(11 answers)
Closed 3 months ago.
I'm trying to translate this jQuery into JavaScript, to save a bit on load time. Here's the line of jQuery:
$('div.annotated p > span.citation').parent().css('display', 'inline')
And here's what I have so far in JavaScript:
document.querySelectorAll('div.annotated p > span.citation').forEach((el) => {})
I'm stuck on how to find the parent of an element, and also apparently how to set the CSS for that element. Should I stick with jQuery, or can JavaScript also do this, and is it much harder?
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:
Change DIV contents using jQuery when link clicked
(6 answers)
Closed 8 years ago.
So, i'm working on this: http://silviucazacu.com/cold and i want to change the content(image&player) when i click on the images in the left.
I want to have all on the same page, but hidden and on image click to appear on center.
Could you be more precise ?
It's kind of easy to do it, you should have researched it.
Edit your img tag like
<img onclick="someJScodethatwillbeexecutedonclicked"></img>
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];