My function checks the hash url, returns its value, uses that value to search for the image (by identifier) ββand applies the class name to it. My console does not show any errors, but I do not see the expected result.
Instead of filtering the .z class by the returned hash value, it writes the entire .z class to id=image
Is there a better way to filter this value and use it as an identifier? Thanks!
JavaScript:
(function($){ $.brantley = function(callback) { var $doc = $(document), $win = $(window), $z, $load, $footer, $header, $status, $container, $hash; $doc.ready(function() { $z = $('.z'); $load = $('#load'); $footer = $('footer'); $header = $('header'); $status = $('#status'); $container = $('#container'), hash = gethash(); if(hash) { var image = hash; $('.z').attr('id', 'image').addClass('active'); } else { $('.z:first').addClass('active'); } }); function gethash() { var hash=window.location.hash; hash=hash.replace(/#/,''); return hash; } function updateNumber(type) { window.location = window.location.pathname + "#" + type; } }; })(jQuery);
EDIT:
Took all the comments into account as well as the answer, here is what I ended up with:
(function($){ $.brantley = function(callback) { var $doc = $(document), $win = $(window), $z, $load, $footer, $header, $status, $container; $doc.ready(function() { $z = $('.z'); $load = $('#load'); $footer = $('footer'); $header = $('header'); $status = $('#status'); $container = $('#container'); var hash = gethash(); if(hash) { $('#' + hash + '.z').addClass('active'); } else { $('.z:first').addClass('active'); } bromance(); }); $win.load(function() { bromance(); $load.fadeOut('fast', function() { $('.active').fadeIn('slow'); $status.fadeIn('slow'); $footer.fadeIn('slow'); }); }); $win.resize(function() { bromance(); }); function gethash() { var hash=window.location.hash; hash=hash.replace(/#/,''); return hash; } function updateNumber(type) { window.location = window.location.pathname + "#" + type; } }; })(jQuery);