Mahran Elneel
Mahran Elneel

Reputation: 196

How Call link tag by id by javascript?

   <img src="images/icon2.png" border=0 onClick="window.document.getElementById('loadimg')">

<a href="images/img.jpg" id='loadimg'></a>

i want when click the image will active the link by id='loadimg' how can i do i try write onClick="window.document.getElementById('loadimg')" but not work

Than you

Upvotes: 0

Views: 689

Answers (2)

Hogan
Hogan

Reputation: 70513

It seems you want the item in the link to be loaded so something like this should work:

window.location.href = window.document.getElementById('loadimg').href;

This will cause the broswer page to navigate to this url.

Or was there something else you wanted to do?

Upvotes: 2

SLaks
SLaks

Reputation: 887305

You can put the image in the link:

<a href="images/img.jpg" id='loadimg'>
    <img src="images/icon2.png" border="0" />    
</a>

Upvotes: 3

Related Questions