add html to div with jQuery

后端 未结 2 1842
-上瘾入骨i
-上瘾入骨i 2021-02-12 16:30

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

$(\"#slideshow\").append(\"

        
相关标签:
2条回答
  • 2021-02-12 16:33

    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>'
    
    0 讨论(0)
  • 2021-02-12 16:48

    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>');
    
    0 讨论(0)
提交回复
热议问题