Matt S
Matt S

Reputation: 91

Image link in JavaScript

I want to make an image link rather than a text link in JavaScript. I'm very new to JavaScript and I just can't figure out why what I've done isn't working! It would work in HTML.

This works (text link 'close [x]'):

    closeLinkString = "<div class='close'><a href='#' id='close-link' onclick=\"Megadropdowns.closeDropDown(); return false;\">close [x]</a></div>", // this is the close button

But for some reason this doesn't:

    closeLinkString = "<div class='close'><a href='#' id='close-link' onclick=\"Megadropdowns.closeDropDown(); return false;\"><img src="/images/loading.gif"></a></div>", // this is the close button

Can anyone help me out with this?

Upvotes: 0

Views: 99

Answers (2)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324620

Any editor with basic colour coding, even your post on this site, would show you immediately that you didn't escape the quotes in the image.

Upvotes: 3

Sirko
Sirko

Reputation: 74036

As you can see from SO's syntax highlighting, you need to escape the " in the image tag by using \" instead:

closeLinkString = "<div class='close'><a href='#' id='close-link' onclick=\"Megadropdowns.closeDropDown(); return false;\"><img src=\"/images/loading.gif\"></a></div>"

Upvotes: 7

Related Questions