-1

I am trying to change url(herf) from style . Check it

<iframe src="https://www.website.com/............" heght="100%" width="100%" >

#document

<!DOCTYPE html>

<html> 
<head></head>
<body>

<a class="class"  href="https://www.website.com/-----"  style="background: url(&quot;https://www.website.com/abc.png&quot;) center center / 100% no-repeat; width: 110px; height: 26px;"></a>

</body>
</html>

<iframe>

I want to change image url with javascript

: style="background: url(&quot;https://www.website.com/abc.png&quot;)

With Another url .

Like that

: style="background: url(&quot;https://www.website.com/xyz.png&quot;)

image xyz.png in important to change.

ChrisM
  • 1,576
  • 6
  • 18
  • 29
  • 1
    When should this change happen? Where is the code you've tried? Possible duplicate of [What do querySelectorAll, getElementsByClassName and other ... return](https://stackoverflow.com/questions/10693845/what-do-queryselectorall-getelementsbyclassname-and-other-getelementsby-method) – Teemu Sep 15 '17 at 12:33

4 Answers4

0
document.getElementsByTagName('iframe')[0].src = "https://www.website.com/xyz.png";

Get the iframe src and update the src. Hope this will help you

Suneha Javid
  • 37
  • 1
  • 2
  • 12
0

To change an element's style from Javascript, you can do so:

<!-- Suppose you have this <a> element -->
<a id="my-link" style="background: ...; ...">...</a>

<!-- This is the code -->
<script>
    document.getElementById("my-link").style.background = "url('https://www.website.com/abc.png') center center / 100% no-repeat";
</script>

Is this what you want?

Luca Polito
  • 2,387
  • 14
  • 20
  • here is problems that id isn't mention in tag just try it with class – Muazam Aziz Sep 15 '17 at 12:51
  • ID isn't important. You can use whatever selector you need to get the element. For example, to get the first link in your iframe: `var element = document.getElementsByTagName("iframe")[0].getElementsByTagName("a")[0];` It is not the most elegant solution, but it should work. – Luca Polito Sep 15 '17 at 12:57
  • can you explain with a example? – Muazam Aziz Sep 15 '17 at 12:59
  • What I mean is: first, you get the link (`var element = ...;`), then you edit its background (`element.style.background = "...";`). – Luca Polito Sep 15 '17 at 13:02
0
<script>
document.getElementById("iframe").setAttribute('style',' background-image: url(https://www.website.com/xyz.png);background-repeat: no-repeat;    background-size: 100% 100%;');
</script>

try this

Suneha Javid
  • 37
  • 1
  • 2
  • 12
0

I have Find it , Try It

<!DOCTYPE html>
<html>
<body>

<ul>
  <li>Coffee</li>
  <li>Tea</li>
</ul>

<p>Click the button to change the text of the first list item (index 0).</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    var list = document.getElementsByTagName("UL")[0];
    list.getElementsByTagName("LI")[0].innerHTML = "Milk";
}
</script>

</body>
</html>