0

I have one line of code that I'm mixing JQuery / HTML but I think I have a syntax error somewhere around the <a href Can anyone spot the issue please?

Here is the code:

$("<div><a href="http://google.com>""+today+"</a></div>")
6
  • 1
    you have " inside ". Commented May 18, 2011 at 19:00
  • 3
    Are you being serious right now? I find it hard to believe that you would take all the time to post this question before checking the simplest of HTML syntax. SO even highlights the problem in your code. I can understand being confused between when to use ' and when to use " - but your href url isn't enclosed in either! Commented May 18, 2011 at 19:03
  • 1
    It's a silly question, but I don't think it deserves a down vote, it's very easy for any JS developer to see the problem and help him out Commented May 18, 2011 at 19:08
  • Try using something like JSLint, it can force you to write cleaner, "syntactically safe" code. Run it manually (jslint.com) or get a plugin for your IDE / text editor. Commented May 18, 2011 at 19:53
  • jlindenbaum: Thanks for the link to jslint.com. I'll check it out. Commented May 18, 2011 at 19:55

2 Answers 2

8

Try this:

$('<div><a href="http://google.com">' + today + '</a></div>');

Alternate:

$("<div><a href=\"http://google.com\">" + today + "</a></div>");

Quotes wrapped in quotes of the same type need to be escaped with a backslash.

You also needed the quotes to wrap the href value correctly.

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

Comments

3

Your leading double quote is cancelling out your href= double quote.

$('<div><a href="link">' + today + '</a></div>');

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.