vidda22
asked on
How to append image to the link by javascript
Hi I've got to add picture to the side of a link.
My question is how do I append image tag to the link via javascript?
the link looks like this:
<li id="35">
<a href="?address=1"> link </a>
</li>
how do i append: <img src="..." /> just after <li>
(I want it to be appended straight after document is ready for display)
??
My question is how do I append image tag to the link via javascript?
the link looks like this:
<li id="35">
<a href="?address=1"> link </a>
</li>
how do i append: <img src="..." /> just after <li>
(I want it to be appended straight after document is ready for display)
??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry there's a typo above (although strangly it works?). It should be
<a href="#" onclick='document.img1.src ="http://images.google.ca/intl/en_ALL/images/logos/images_logo_lg.gif;"'>Link </a>
<p>
<img src ="http://a.gif" name="img1">
<a href="#" onclick='document.img1.src
<p>
<img src ="http://a.gif" name="img1">
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That assumes a single li of id='35'.
Alternatively:
items = document.getElementsByTagN ame('li') OR containingListElement.getE lementsByT agName('li ');
for(i = 0; i < items.length; i++)
{
item.innerHTML = '<img src="..." />' + item.innerHTML;
}
I just prefer using jquery since it generally works in any browser you throw at it.
Alternatively:
items = document.getElementsByTagN
for(i = 0; i < items.length; i++)
{
item.innerHTML = '<img src="..." />' + item.innerHTML;
}
I just prefer using jquery since it generally works in any browser you throw at it.
Open in new window