mtwallet
mtwallet

Reputation: 5086

add html to div with jQuery

I am trying to add some additional html to a div with id slideshow using jQuery. My code:

$("#slideshow").append("<a id="prev" title="Previous Slide">Previous Slide</a><a id="next" title="Next Slide">Next Slide</a>");

This isn't working, can anyone tell me what I am doing wrong?

Upvotes: 25

Views: 78100

Answers (2)

mcgrailm
mcgrailm

Reputation: 17640

your not escaping your quotes best way to fix is to put the append in single quotes

$("#slideshow").append('<a id="prev" title="Previous Slide">Previous Slide</a><a id="next" title="Next Slide">Next Slide</a>');

Upvotes: 3

SLaks
SLaks

Reputation: 887413

You're mixing quotes.

Your string goes from the first " to the second ", meaning that the string only contains "<a id=". The string is followed by the identifier prev, then another string, creating a syntax error.

Change the outer quotes around the string to ', like this:

'<a id="prev" title="Previous Slide">Previous Slide</a><a id="next" title="Next Slide">Next Slide</a>'

Upvotes: 30

Related Questions