Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jQuery selector scoping technique using currying
<html>
...
<body class="<%= "#{params[:controller]} #{params[:action]}" %>">
...
</body>
</html>
// lib/jquery_extensions.js
var setSelectorContext = function(container) {
return function(query) {
return $(container).find(query)
}
}
// app/assets/javascripts/user.js
$(function() {
var $$$ = setSelectorContext('.users.index')
$$$('.profile') == $('.users.index .profile') // returns true
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment