0

I have a HTML structure like this:

<div>some texts</div>
<span>
    something
    <a href="#">link</a>
</span>
<img src="#" height='35' width='35' />

I'm trying to change the color of that link <a> when user goes on that image <img>. (goes on that element = :hover). Noted that this doesn't work:

img:hover a {
    color: red;
}

Doing that is possible?


If doing what I want in above isn't possible, what about this HTMM structure?

<a><img src="#" height='35' width='35' /></a>
<div>
    some texts
    <span><a href="#">link</a>
    </span>
</div>

In this case I want to change the color of that inner <a> when user goes on that image <img> (:hover).

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Martin AJ
  • 6,261
  • 8
  • 53
  • 111
  • var doc = document; var div = doc.getElementsByTagName('div'); var anchor = doc.getElementsByTagName('a'); var img = doc.getElementsByTagName('img'); img[0].addEventListener("mouseover", function(){ anchor[0].style.color = "red"; }); img[0].addEventListener("mouseout", function(){ anchor[0].style.color = "blue"; }); – Ronnie Royston Jul 11 '16 at 17:20
  • @RonRoyston Actually I don't want to do that by JS .. thank you anyway. – Martin AJ Jul 11 '16 at 19:15
  • ...just curious, why not? – Ronnie Royston Jul 11 '16 at 21:04
  • @RonRoyston Because if JS be deactivate on the user's browser, then my website design will be damaged.. In other word the CSS is broken. – Martin AJ Jul 11 '16 at 21:34
  • Warning ! Because your browser does not support HTML5, some elements are created using JavaScript. Unfortunately your browser has disabled scripting. Please enable it in order to display this page. – Ronnie Royston Jul 12 '16 at 01:43

0 Answers0