/    Sign up×
Community /Pin to ProfileBookmark

Put inline JavaScript in the head

Hi,

The following code works:

[CODE]<html>
<head>
<style type=”text/css”>
img
{
opacity:0.4;
filter:alpha(opacity=40);
}
</style>
</head>
<body>

<img src=”http://www.w3schools.com/Css/klematis.jpg” width=”150″ height=”113″ alt=”klematis”
onmouseover=”this.style.opacity=1;this.filters.alpha.opacity=100″
onmouseout=”this.style.opacity=0.4;this.filters.alpha.opacity=40″ />

<img src=”http://www.w3schools.com/Css/klematis2.jpg” width=”150″ height=”113″ alt=”klematis”
onmouseover=”this.style.opacity=1;this.filters.alpha.opacity=100″
onmouseout=”this.style.opacity=0.4;this.filters.alpha.opacity=40″ />

</body>
</html>[/CODE]

But the problem is you have to repeat the inline JavaScript for all the img tags. I tried to put the script in the head to no avail:

[CODE]<html>
<head>
<style type=”text/css”>
img
{
opacity:0.4;
filter:alpha(opacity=40);
}
</style>
<script type=”text/javascript”>
function getElements()
{
var x=document.getElementsByTagName(“img”);
x.style.opacity=1; x.filters.alpha.opacity=100;
}
</script>
</head>
<body>

<img src=”http://www.w3schools.com/Css/klematis.jpg” width=”150″ height=”113″ alt=”klematis”
onmouseover=”getElements()”
onmouseout=”this.style.opacity=0.4;this.filters.alpha.opacity=40″ />

<img src=”http://www.w3schools.com/Css/klematis2.jpg” width=”150″ height=”113″ alt=”klematis”
onmouseover=”getElements()”
onmouseout=”this.style.opacity=0.4;this.filters.alpha.opacity=40″ />

</body>
</html>[/CODE]

Everything seems right to me, but it doesn’t work.

Many thanks for any help!
Mike

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Rain_Lover spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...