Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 144
  • Last Modified:

javascript quotes within quotes

This is probably a rather simple question, but web searching has turned up the wrong answers. I have the following line in an html file:

onmouseover="document.body.style.cursor='pointer'; this.style.backgroundImage=\"url ('images/E-hover.png')\";"

It doesn't work with quotes escaped as shown. How do I make this work?
2 Solutions
Tom BeckCommented:
Try this. The background image url should work without quotes.

onmouseover="document.body.style.cursor='pointer'; this.style.backgroundImage='url (images/E-hover.png)';"
RobOwner (Aidellio)Commented:
Or keep your quoting style the same (single inside, double outside): http://jsbin.com/difaye/1/edit?html,output

onmouseover="document.body.style.cursor='pointer'; this.style.backgroundImage='url(\'images/E-hover.png\')'"
jmarkfoleyAuthor Commented:
Both of those ideas worked! Good to know both. Rob Jurd's will work if I have a URL with embedded spaces.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now