Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript How can i simplify my ugly jQuery? (code included lol) Re: How can i simplify my ugly jQuery? (code included lol)

#103088
Johnnyb
Member

Couldn’t you just grab the ID from whatever button’s clicked like so…

$('.navigation a').click(function(e) {
e.preventDefault();
var $self = $(this);
// some code here to hide the page if it is open...
$('.contentWrap').load($self.attr('id') + '.html', function() {
$(this).fadeIn('slow');
});
});‚Äč

So long as the anchor id matches the html file name then it should load in that file. I prefer Karl’s method though so that you can link to that page directly.