Instantly share code, notes, and snippets.

Embed
What would you like to do?
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