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?
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.
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.
Note: The contents or elements inserted using the jQuery before() and after() methods is added outside of the selected elements.
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.
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>'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With