开发者

prepend href with same class

I have the following code on the my p开发者_JAVA技巧age...

<a href="javascript:change_product_photo(2);"><img id="alternate_product_photo_2"    style="border-color:#666666;" src="/v/vspfiles/photos/00-6189-2S.jpg" border="1">

Sometimes there could be more of the <a href="javascript:change_product_photo(4);"> and each one would have a higher index number 5, 6 ,7, etc.

What I want to do is for each and every instance of the href with javascript:change_product_photo(x) (where x is the index) remove both "_" from the change_product_link but leave the (x) index

My thought was to first add a class to all hrefs that contain javascript:change_product_photo and then modify all of the href;s with that class but I am lost on how to do this.

Here is what I got so far...

$("a[href*='javascript:change_product_photo']").addClass('link_fix');

Now I don't know how to remove the "_" from the url.


try...

$("a[href^='javascript:change_product_photo']")
    .addClass('link_fix')
    .attr('href', function(i,v){
        return v.replace('_','');
    })

edit based on comment, note the href*= has changed to href^= (start-with selector)

and read 'Easy Setter Functions' function(i,v){...} as of jQuery 1.4.x

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜