jquery - Setting the id of a link based on it's href -



jquery - 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 url after each / , create array of each var pfn = buttlinkarray[2]; // want 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 set id on each button based on href when user "mouseover's" it. know how can done automatically when page loads, each button in list gets , id based on it's href, without user interaction.

thanks,

dan

iterate through links on page load. if using jquery 1.7+ utilize prop set href attribute. otherwise utilize attr.

$('.portfoliothumbs ul li a').each( function(){ var buttlink = $(this).attr('href') //do want attr or want prop? var buttlinkarray = buttlink.split( '/' ); // split url after each / , create array of each var pfn = buttlinkarray[2]; // want portfolio folder name var url = window.location.pathname; $(this).prop('href', url); } );

jquery jquery-selectors href attr

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -