Using jQuery, I am trying to automatically replace every...
www.mywebsite.com/blog/category/categoryname
by
ww开发者_运维问答w.mywebsite.com/blog/#categoryname
...in my page.
$("a[href^='...']")
.each(function()
{
this.href = this.href.replace(...);
}
);
Can someone help with the syntax please?
I assume /category/
is actual, but categoryname
varies. If that's correct, do this:
this.href = this.href.replace( '/category/', '/#' );
or a similar approach:
this.href = this.href.split('/category/').join('/#');
$('a[href*=category]').attr('href', function(i,h){ return h.replace(/category\//,'#'); });
I ended up using the following
$(".cat-menu a[href*=category]")
.each(function()
{
this.href = this.href.replace( "/category/", "/#" );
}
);
Thank you
精彩评论