What does it mean. $ ('. Selector') in jQuery?

I see this in someone's code: this.$('.selector') and I'm curious what this does. "this" is a layout view. So what is the prefix "this." to the jQuery selector in this context, execute?

+8
javascript scope jquery
source share
3 answers

In doc :

$ (jQuery or Zepto). $ (selector)

If jQuery or Zepto is included in the pages, each view has a $ function that runs the queries that are covered within the view element. If you use this jQuery function with a scope, you should not use model identifiers as part of your query to pull out specific elements in a list and can rely more on attributes of the HTML class. This is equivalent to running: view.$el.find(selector)

 ui.Chapter = Backbone.View.extend({ serialize : function() { return { title: this.$(".title").text(), start: this.$(".start-page").text(), end: this.$(".end-page").text() }; } }); 

In short, he used to access some View elements with familiar syntax.

+9
source share

This basically limits the search for elements with the selector class to the element on which your view is based.

+2
source share

It basically changes the search scope from document to this , which is obviously some element.

0
source share

All Articles