0

I have a <div> element that when clicked updates content on a page. How do I go about adding a link with this JS code? I made a JSFiddle of basically my question. Basically the "" are ending too soon so there must be a character like %20 to do my dirty work. Is it possible?

http://jsfiddle.net/BpCSm/

$("#content").html("<a herf="http://www.google.com">google.com</a>");
ajp15243
  • 7,384
  • 1
  • 31
  • 38
Michael Schmidt
  • 384
  • 3
  • 14

2 Answers2

4

Use single quotes inside the double quotes:

$("#content").html("<a href='http://www.google.com'>google.com</a>"); } ); });

Also, it's not herf but href

This is the adapted Fiddle: http://jsfiddle.net/Kennethtruyers/BpCSm/4/

Kenneth
  • 27,326
  • 6
  • 58
  • 82
1

There are 2 ways to handle this

Using combination of singlequote and doublequote like this "'" or '"'

$("#content").html("<a href='http://www.google.com'>google.com</a>");

or , using the escape character like this "\"" or '\''

$("#content").html("<a href=\"http://www.google.com\">google.com</a>");
Rohit Agrawal
  • 5,096
  • 5
  • 17
  • 29