treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Simple Append Not Working (jQuery)

  • Hey guys,

    I'm just trying to use this code:

    <script type="text/javascript">
    $function() {
    $('div.entry-text blockquote').prepend("<span class="left"></span>");
    $('div.entry-text blockquote').append("<span class="right"></span>");
    });
    </script>


    In a Wordpress site for the blog. Just want a simple way to get left and right quotes in each blockquote. This code was pasted in the footer. In the header, this is called:

    <?php wp_enqueue_script("jquery"); ?>


    Anything I'm not doing right?

    - Steph
  • Hey, have you tested that the function is running by using a simple alert('this runs!!'); ? If it doesn't run then try using $(document).ready(function(){ instead of $function(){. If it does run then maybe try putting in a manual link to your jquery file rather than using the enqueue method.

    Also, are you putting content into the spans dynamically? As there doesn't appear to be any quotation marks within the spans in your code.
  • You have a typo.

    You notice how you end in }); ? Do you see the opening parenthesis?

    Change
    $function() {
    to
    $(function() {
    and you'll be fine.
  • Thank you! That just about fixed it. Turns out I also had double quotes inside of double quotes, so it was conflicting.

    This is what I ended up with that did the job:

    $(function() {
    $('div.entry-text blockquote').prepend('<span class="left">&quot;</span>');
    $('div.entry-text blockquote').append('<span class="right">&quot;</span>');
    });
  • Oh yes, that is true, double double quotes are no good.
    Congrats