Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add html to div with jQuery

Tags:

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?

like image 756
mtwallet Avatar asked May 05 '10 14:05

mtwallet


People also ask

How append HTML data to div in jQuery?

jQuery append() MethodThe append() method inserts specified content at the end of the selected elements. Tip: To insert content at the beginning of the selected elements, use the prepend() method.

What is HTML append?

append( function ) function. Type: Function( Integer index, String html ) => htmlString or Element or Text or jQuery. A function that returns an HTML string, DOM element(s), text node(s), or jQuery object to insert at the end of each element in the set of matched elements.

Which jQuery function adds HTML content outside a selection?

Note: The contents or elements inserted using the jQuery before() and after() methods is added outside of the selected elements.

What is insertAfter in jQuery?

jQuery insertAfter() Method The insertAfter() method inserts HTML elements after the selected elements. Tip: To insert HTML elements before the selected elements, use the insertBefore() method.


1 Answers

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>' 
like image 126
SLaks Avatar answered Nov 07 '22 03:11

SLaks