views:

80

answers:

3

The code which I am analysing

var id = $(this).parents('div.answer').attr('id').split('_')[1];

I have searched unsuccessfully documentation for the method parents in Google by

Javascript "parents("

and by

Java "parents("

How can you find the documentation for the following methods in JavaScript?

parents()
attr()
split()
+4  A: 

this is not (as you put it) javascript method, but a jQuery method. $ itself is an alias for the jQuery "class", therefore $() constructs a new jQuery object, on which you then invoke methods. Have a look at jQuery documentation.

Peter Perháč
A: 

This site has most javascript methods: http://www.java2s.com/Code/JavaScriptReference/Javascript-Methods/CatalogJavascript-Methods.htm

chills42
+5  A: 

Parents() and attr() are jQuery methods, not native JavaScript methods.

jQuery is a JavaScript library that adds a lot of helpful functionality:

http://jquery.com/

Here's the documentation for parents:

http://docs.jquery.com/Traversing/parents

Here's attr:

http://docs.jquery.com/Attributes/attr

Split, however, is a javascript method that splits a string into an array using a delimiter:

http://www.w3schools.com/jsref/jsref_split.asp

Usually when you see this notation:

$(this)

it's a good indication its jQuery:

http://docs.jquery.com/Core/jQuery

That implies you're working with jQuery. $() is a jQuery construct for the jQuery core.

danieltalsky