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>");
2
  • 1
    The following SO ticket has the answer for you. stackoverflow.com/questions/4772774/… Commented May 28, 2013 at 22:10
  • 2
    Please look at the console when running your code, you will see you have syntax errors.. Commented May 28, 2013 at 22:13

2 Answers 2

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/

Sign up to request clarification or add additional context in comments.

1 Comment

No problem. Please don't forget to up vote / accept an answer if it helped you
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>");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.