Javascript/Jquery change anchor link using regex -
<ul id="nav"> <li><a href="index.html#section1">natural beauty</a></li> <li><a href="index.html#section2">beginings</a></li> <li><a href="index.html#section3">earth's purity</a></li> <li><a href="index.html#section4">bottling goodness</a></li> <li><a href="index.html#section5">drink health</a></li> <li><a href="index.html#section6">minerals</a></li> <li><a href="#">contact us</a></li> </ul>
i looked possible js/jquery on how jump page in href, header print index.html. tried change href this:
$(document).ready(function(){ $('a').each(function(){ var value = $(this).attr('href'); var x = 'index.html'+ (#[a-z\d-]+); $(this).attr('href', value.replace(x,'index.html')); }); });
it didn't work out, because header still print index.html#section. need here. thanks
you need use regexp constructor when concatenating 2 regex patterns. change below statements,
var x = 'index.html'+ (#[a-z\d-]+); $(this).attr('href', value.replace(x,'index.html'));
to,
$(this).attr('href', value.replace(/index\.html#[a-z\d-]+/,'index.html'));
Comments
Post a Comment