Search code examples
javascriptjqueryparents

jQuery parents() example not working


Hello everyone and thank you for your time,

I have been fiddling with jQuery recently (in short, I'm a newbie) and I was interested in the "parents()" method. In the article on jquery.com, they show an example that allows to display every parent of a < b > tag.

Here is the link: https://api.jquery.com/parents/

And the script in the example:

<script>
var parentEls = $( "b" ).parents()
  .map(function() {
    return this.tagName;
  })
  .get()
  .join( ", " );
$( "b" ).append( "<strong>" + parentEls + "</strong>" );
</script>

Well, I tried to recreate this example on jsfiddle.net to really understand how it works, I simply copy & pasted but alas it doesn't work. I'm at a loss as for why it wouldn't work so I ask kindly if I did anything wrong in copying the example.

Here is the link: http://jsfiddle.net/a84f7L46/1/

Thanks in advance for your precious help!

JM


Solution

  • On the left side of JSfiddle you didn't choose the library/framework.

    Select jQuery 1.8.3 and it works.