Skip to content

Instantly share code, notes, and snippets.

@vsakaria
Last active September 26, 2016 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsakaria/cb8be82a7171220b95e3a70cf5a5dbb2 to your computer and use it in GitHub Desktop.
Save vsakaria/cb8be82a7171220b95e3a70cf5a5dbb2 to your computer and use it in GitHub Desktop.
Demonstrating my understanding of call and apply
var ComparisonTable = (function ($) {
var init = function () {
$("td, th").on('mouseenter',function() {
var col = $(this).parent().children().index($(this));
$('.eh-column').each(function () {
$(this).removeClass();
});
$('#column-' col).attr('class', 'column-boarder');
});
$("td, th").on('mouseleave',function() {
var col = $(this).parent().children().index($(this));
$('.eh-column').each(function () {
$(this).removeClass();
});
$('#column-' col).attr('class', 'table-compare-products-v2');
});
};
return {
init: init
};
})(jQuery);
/////////////ANSWER/////////////////////////////////////////////////////////////////////////
var ComparisonTable = (function ($) {
var init = function () {
$("td, th").on('mouseenter',function() {
var col = getColumn.call(this);
handleStyling.call(this);
$('#column-' col).attr('class', 'column-boarder');
});
$("td, th").on('mouseleave',function() {
var col = getColumn.call(this);
handleStyling.call(this);
$('#column-' col).attr('class', 'table-compare-products-v2');
});
};
var handleStyling = function () {
$('.eh-column').each(function () {
$(this).removeClass();
});
};
var getColumn = function () {
return $(this).parent().children().index($(this));
};
return {
init: init
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment