Skip to main content

Posts

Showing posts with the label attr

Setting the id of a link based on it"s href

$('.portfolioThumbs ul li a').mouseover( function(){ var buttLink = $(this).attr('href') var buttLinkArray = buttLink.split( '/' ); // Split the URL after each / and Create an array of each var pFN = buttLinkArray[2]; // We want the Portfolio Folder Name var url = window.location.pathname; $('.galleryNav ul li a').removeClass('hovered'); $('.galleryNav ul li a' + '#' + pFN).addClass('hovered'); window.location.pathname = url + '#' + pFN; } ); This code allows me to set an ID on each button based on its href when the user "mouseover's" it. Does anyone know how this can be done automatically when the page loads, so that each button in the list gets and ID based on it's href, without any user interaction. Thanks, Dan